FatFS/documents/res/app2.c
savelij13 a6bc2e0f07 fatfs v0.13 May 21, 2017:
- Changed heading character of configuration keywords "_" to "FF_".
- Removed ASCII-only configuration, FF_CODE_PAGE = 1. Use FF_CODE_PAGE = 437 instead.
- Added f_setcp(), run-time code page configuration. (FF_CODE_PAGE = 0)
- Improved cluster allocation time on stretch a deep buried cluster chain.
- Improved processing time of f_mkdir() with large cluster size by using FF_USE_LFN = 3.
- Improved NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous.
- Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12)
- Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c)
- Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c)
2025-09-11 10:28:54 +03:00

69 lines
1.4 KiB
C

/*------------------------------------------------------------/
/ Remove all contents of a directory
/ This function works regardless of FF_FS_RPATH.
/------------------------------------------------------------*/
FILINFO fno;
FRESULT empty_directory (
char* path /* Working buffer filled with start directory */
)
{
UINT i, j;
FRESULT fr;
DIR dir;
fr = f_opendir(&dir, path);
if (fr == FR_OK) {
for (i = 0; path[i]; i++) ;
path[i++] = '/';
for (;;) {
fr = f_readdir(&dir, &fno);
if (fr != FR_OK || !fno.fname[0]) break;
if (_FS_RPATH && fno.fname[0] == '.') continue;
j = 0;
do
path[i+j] = fno.fname[j];
while (fno.fname[j++]);
if (fno.fattrib & AM_DIR) {
fr = empty_directory(path);
if (fr != FR_OK) break;
}
fr = f_unlink(path);
if (fr != FR_OK) break;
}
path[--i] = '\0';
closedir(&dir);
}
return fr;
}
int main (void)
{
FRESULT fr;
FATFS fs;
char buff[256]; /* Working buffer */
f_mount(&fs, "", 0);
strcpy(buff, "/"); /* Directory to be emptied */
fr = empty_directory(buff);
if (fr) {
printf("Function failed. (%u)\n", fr);
return fr;
} else {
printf("All contents in the %s are successfully removed.\n", buff);
return 0;
}
}