初级会员

- 积分
- 138
- 金钱
- 138
- 注册时间
- 2021-2-9
- 在线时间
- 36 小时
|
FRESULT filedir_delete(u8 *path)//删除路径下每一个文件
{
u8 i, j;
FRESULT res;
DIR dir;
FILINFO fno;
u8 *path1;
#if _USE_LFN
fno.lfname = 0; /* Set null pointer because LFN is not needed */
#endif
res = f_opendir(&dir,(const TCHAR*)path);
if (res == FR_OK)
{
for (i = 0; path[i]; i++)
{
path1[i]=path[i];
}
path1[i++] = '/';
for (;;)
{
res = f_readdir(&dir, &fno);
if (res != FR_OK || !fno.fname[0]) break;//错误了或到末尾了,退出
if (fno.fname[0] == '.') continue;//忽略上级目录
j = 0;
do
path1[i+j] = fno.fname[j];
while (fno.fname[j++]);
if (fno.fattrib & AM_DIR)//判断是否是文件夹
{
res = filedir_delete(path1);//该函数下还有非空文件夹
if (res != FR_OK) break;
}
else
{
res = f_unlink((const TCHAR*)path1);
if ((res != FR_OK) && (res != FR_DENIED)) break;
}
}
path1[--i] = '\0';
}
return res;
}
用usmart组件调用这个函数就卡死
|
|