2020-09-07 12:49 PM
Hi Community, I am working on a project which has Sd card with spi and using FATFS library.I want to store id ,parent id and short filename of all directories and subdirectories not files
for example for this diagram my output will like :
id /name /parent id
1 / / /1
2 / bin /1
3 / usr /1
4 / local /3
5 / bin /3
6 / ucb /3
7 / home/ 1
8 / mkl /7
9 / mystuff /8
10 /stuff /9
11 /private/ 8
12 /hun /7
13 /hisstuff /12
14 /publick /12
15 /stuff /14
16 /other /7
i have researched the library and find this scanning function I can print all directory and subdirectories with id but no luck with parent ids any suggestion would be good for me
uint8_t id;
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 (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
if (fno.fattrib & AM_DIR) { /* It is a directory */
id++;
printf("%d %s",id,fno.altname);
i = strlen(path);
sprintf(&path[i], "/%s", fno.fname);
res = scan_files(path); /* Enter the directory */
if (res != FR_OK) break;
path[i] = 0;
}
}
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;
}