https://elm-chan.org/fsw/ff/doc/readdir.html
[C] 纯文本查看 复制代码 /* Recursive scan of all items in the directory */
FRESULT scan_files (
char* path /* Start node to be scanned (***also used as work area***) */
)
{
FRESULT res;
DIR dir;
UINT i;
static FILINFO fno;
res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
for (;;) {
res = f_readdir(&dir, &fno); /* Read a directory item */
if (fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) { /* The item is a directory */
i = strlen(path);
sprintf(&path[i], "/%s", fno.fname);
res = scan_files(path); /* Enter the directory */
if (res != FR_OK) break;
path[i] = 0;
} else { /* The item is a file. */
printf("%s/%s\n", path, fno.fname);
}
}
f_closedir(&dir);
}
return res;
}
int main (void)
{
FATFS fs;
FRESULT res;
char buff[256];
res = f_mount(&fs, "", 1);
if (res == FR_OK) {
strcpy(buff, "/");
res = scan_files(buff);
}
return res;
}
|