我有一个类似的问题。这是我的代码。希望你觉得这有帮助
#define FW_FOLDER "fw"
#define FW_PATH "0:/" FW_FOLDER
#define FW_BIN "*.bin"
FRESULT res;
DIR dir;
FILINFO fno;
static char fw_path[128];
// Find first item
res = f_findfirst(&dir, &fno, FW_PATH, FW_BIN);
// Create directory (optional)
if (res == FR_NO_PATH)
{
printf("Creating %s directory!\n", FW_FOLDER);
f_mkdir(FW_FOLDER);
}
// Repeat until proper item is found
while (res == FR_OK)
{
// Make sure file name is valid
if (fno.fname[0] == 0)
break;
// Debugging
printf("Scanning: %s\n", fno.fname);
// Make sure it is not a directory
if (!(fno.fattrib & AM_DIR))
{
// Success!
printf("Found: %s\n", fno.fname);
// Construct file path
sprintf(fw_path, "%s/%s", FW_PATH, fno.fname);
break;
}
// Move to the next one
res = f_findnext(&dir, &fno);
}
// Close directory
f_closedir(&dir);
是的,您需要FF_USE_FIND == 1
在 fatfs 库中启用。如果你决定使用2
forFF_USE_FIND
你必须检查altname
作为fno
.
另外,我最终不得不将文件验证更新到这个片段
// Make sure file name is alpha numeric
if (!isalnum(fat_fno.fname[0]))
break;