]>
cloudbase.mooo.com Git - z180-stamp.git/blob - fatfs/doc/img/app2.c
1 /*------------------------------------------------------------/
2 / Remove all contents of a directory
3 / This function works regardless of _FS_RPATH.
4 /------------------------------------------------------------*/
7 FRESULT
empty_directory (
8 char* path
/* Working buffer filled with start directory */
17 fno
.lfname
= 0; /* Disable LFN output */
19 fr
= f_opendir(&dir
, path
);
21 for (i
= 0; path
[i
]; i
++) ;
24 fr
= f_readdir(&dir
, &fno
);
25 if (fr
!= FR_OK
|| !fno
.fname
[0]) break;
26 if (_FS_RPATH
&& fno
.fname
[0] == '.') continue;
29 path
[i
+j
] = fno
.fname
[j
];
30 while (fno
.fname
[j
++]);
31 if (fno
.fattrib
& AM_DIR
) {
32 fr
= empty_directory(path
);
33 if (fr
!= FR_OK
) break;
36 if (fr
!= FR_OK
) break;
51 char buff
[64]; /* Working buffer */
57 strcpy(buff
, "/"); /* Directory to be emptied */
58 fr
= empty_directory(buff
);
61 printf("Function failed. (%u)\n", fr
);
64 printf("All contents in the %s are successfully removed.\n", buff
);