使用 Virtual Filesystem 读取 SD-card 中文件名不完整问题

ESP_@In逍遥子
Posts: 132
Joined: Thu Nov 15, 2018 2:06 am

使用 Virtual Filesystem 读取 SD-card 中文件名不完整问题

Postby ESP_@In逍遥子 » Fri Nov 16, 2018 10:25 am

[问题描述]:
基于 sd_card 示例,试图读取 sd_card 中的所有文件,保存文件名到字符数组 directory 中。发现文件名前缀超过 6 个字符会不完整,只有前面的 6 个字符余下的显示 ~[数字:例如1、2、3]. 前缀重复的后面的数字会不同。
怎样可以得到完整的文件名呢? 谢谢

[打印结果]:

Code: Select all

[Codebox=c file=Untitled.c]
/sdcard/NEW_ME~1.MP3
/sdcard/SEEYOU.MP3
/sdcard/CAMKEL~1.MP3
/sdcard/CRAZYF~1.MP3
/sdcard/DARIN-~1.MP3
/sdcard/EMBLEM~1.MP3
/sdcard/OMFG-H~1.MP3
/sdcard/TAYLOR~1.MP3
/sdcard/TAYLOR~2.MP3
/sdcard/TAYLOR~3.MP3
/sdcard/TAYLOR~4.MP3
[/Codebox]
[代码如下]:

Code: Select all

[Codebox=c file=Untitled.c]
    void sdmmc_mount() 
    {
        sdmmc_host_t host = SDMMC_HOST_DEFAULT();

        sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
        slot_config.gpio_cd = (gpio_num_t)34;

        esp_vfs_fat_sdmmc_mount_config_t mount_config = {
            .format_if_mount_failed = false,
            .max_files = 5,
            .allocation_unit_size = 16 * 1024
        };

        esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
    }
    void read_content(const char* path, uint8_t *filecount)
    {
        char nextpath[100];
        struct dirent* de;
        DIR* dir = opendir(path);
        while (1) {
            de = readdir(dir);
            if(!de) {
                return;
            } else if (de->d_type == DT_REG) {
                if (strstr(de->d_name, ".mp3") || strstr(de->d_name, ".MP3") ) {
                    sprintf(directory[*filecount], "%s/%s", path, de->d_name);
                    printf("%s\n", directory[*filecount]);
                    (*filecount)++;
                }
            } else if (de->d_type == DT_DIR) {
                sprintf(nextpath, "%s/%s", path, de->d_name);
                read_content(nextpath, filecount);
            }
        }
        closedir(dir);
    }
[/Codebox]

ESP_igrr
Posts: 2071
Joined: Tue Dec 01, 2015 8:37 am

Re: 使用 Virtual Filesystem 读取 SD-card 中文件名不完整问题

Postby ESP_igrr » Fri Nov 16, 2018 10:36 am

This is called "8.3 names". You can enable long filename support in FATFS in menuconfig. See CONFIG_FATFS_LONG_FILENAMES. When enabling, keep in mind that Microsoft used to have patents for long filename support, in some countries.

ESP_@In逍遥子
Posts: 132
Joined: Thu Nov 15, 2018 2:06 am

Re: 使用 Virtual Filesystem 读取 SD-card 中文件名不完整问题

Postby ESP_@In逍遥子 » Fri Nov 16, 2018 11:08 am

Thank you very much!

Who is online

Users browsing this forum: No registered users and 37 guests