]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/documents/res/app2.c
1 /*------------------------------------------------------------/
2 / Remove all contents of a directory
3 / This function works regardless of FF_FS_RPATH.
4 /------------------------------------------------------------*/
9 FRESULT
empty_directory (
10 char* path
/* Working buffer filled with start directory */
17 fr
= f_opendir(&dir
, path
);
19 for (i
= 0; path
[i
]; i
++) ;
22 fr
= f_readdir(&dir
, &fno
);
23 if (fr
!= FR_OK
|| !fno
.fname
[0]) break;
24 if (_FS_RPATH
&& fno
.fname
[0] == '.') continue;
27 path
[i
+j
] = fno
.fname
[j
];
28 while (fno
.fname
[j
++]);
29 if (fno
.fattrib
& AM_DIR
) {
30 fr
= empty_directory(path
);
31 if (fr
!= FR_OK
) break;
34 if (fr
!= FR_OK
) break;
49 char buff
[256]; /* Working buffer */
55 strcpy(buff
, "/"); /* Directory to be emptied */
56 fr
= empty_directory(buff
);
59 printf("Function failed. (%u)\n", fr
);
62 printf("All contents in the %s are successfully removed.\n", buff
);