Solved
FATFS: show all files
Hi,
is it possibility to show a list of files and folders with the fatfs library?
Like "ls" in the console.
Hi,
is it possibility to show a list of files and folders with the fatfs library?
Like "ls" in the console.
The FatFs library provides you with the means to implement this, but not the code, although you might find some if you look.
Typically a problem that can be solved via recursive, or queued linear, traversal
For a simple single level
puts("Display Directory");
{
DIR dir;
char *path;
UINT BytesWritten;
char string[128];
path = ""; // where you want to list
res = f_opendir(&dir, path);
#ifdef DBG
if (res != FR_OK)
printf("res = %d f_opendir\n", res);
#endif
if (res == FR_OK)
{
while(1)
{
FILINFO fno;
res = f_readdir(&dir, &fno);
#ifdef DBG
if (res != FR_OK)
printf("res = %d f_readdir\n", res);
#endif
if ((res != FR_OK) || (fno.fname[0] == 0))
break;
sprintf(string, "%c%c%c%c %10d %s/%s",
((fno.fattrib & AM_DIR) ? 'D' : '-'),
((fno.fattrib & AM_RDO) ? 'R' : '-'),
((fno.fattrib & AM_SYS) ? 'S' : '-'),
((fno.fattrib & AM_HID) ? 'H' : '-'),
(int)fno.fsize, path, fno.fname);
puts(string);
}
}
}Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.