基于 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]