STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
app2.c
Go to the documentation of this file.
1 /*------------------------------------------------------------/
2 / Remove all contents of a directory
3 / This function works regardless of _FS_RPATH.
4 /------------------------------------------------------------*/
5 
6 
8  char* path /* Working buffer filled with start directory */
9 )
10 {
11  UINT i, j;
12  FRESULT fr;
13  DIR dir;
14  FILINFO fno;
15 
16 #if _USE_LFN
17  fno.lfname = 0; /* Disable LFN output */
18 #endif
19  fr = f_opendir(&dir, path);
20  if (fr == FR_OK) {
21  for (i = 0; path[i]; i++) ;
22  path[i++] = '/';
23  for (;;) {
24  fr = f_readdir(&dir, &fno);
25  if (fr != FR_OK || !fno.fname[0]) break;
26  if (_FS_RPATH && fno.fname[0] == '.') continue;
27  j = 0;
28  do
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;
34  }
35  fr = f_unlink(path);
36  if (fr != FR_OK) break;
37  }
38  path[--i] = '\0';
39  closedir(&dir);
40  }
41 
42  return fr;
43 }
44 
45 
46 
47 int main (void)
48 {
49  FRESULT fr;
50  FATFS fs;
51  char buff[64]; /* Working buffer */
52 
53 
54 
55  f_mount(&fs, "", 0);
56 
57  strcpy(buff, "/"); /* Directory to be emptied */
58  fr = empty_directory(buff);
59 
60  if (fr) {
61  printf("Function failed. (%u)\n", fr);
62  return fr;
63  } else {
64  printf("All contents in the %s are successfully removed.\n", buff);
65  return 0;
66  }
67 }
68 
69 
70 
FRESULT f_unlink(const TCHAR *path)
Definition: ff.c:3600
Definition: ff.h:151
Definition: ff.h:78
#define _FS_RPATH
Definition: ffconf.h:190
FRESULT f_readdir(DIR *dp, FILINFO *fno)
Definition: ff.c:3348
FRESULT empty_directory(char *path)
Definition: app2.c:7
FRESULT
Definition: ff.h:198
FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt)
Definition: ff.c:2475
int main(void)
Definition: app2.c:47
FRESULT f_opendir(DIR *dp, const TCHAR *path)
Definition: ff.c:3260
TCHAR fname[13]
Definition: ff.h:187
unsigned int UINT
Definition: integer.h:25
Definition: ff.h:199
Definition: ff.h:182
#define AM_DIR
Definition: ff.h:335
BYTE fattrib
Definition: ff.h:186