1.SD卡删除空文件夹

This commit is contained in:
payton 2023-11-17 11:14:36 +08:00
parent 0424017f99
commit d3745ff4aa

View File

@ -669,6 +669,34 @@ static void trave_file(char* path)
return;
}
int sf_is_directory_empty(const char *path)
{
DIR *dir = opendir(path);
if (dir == NULL) {
MLOGE("Error opening directory");
return -1;
}
struct dirent *entry;
int count = 0;
while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
count++;
break;
}
}
closedir(dir);
if (count == 0) {
return 1;
} else {
return 0;
}
}
int sf_dcf_resort_min(void)
{
@ -706,6 +734,13 @@ int sf_dcf_resort_min(void)
MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey);
if(gLastFileKey <= MAX_DCF_FILE_NUM)
{
sprintf(sTmp,"%s/%d%s",sRootPath,gLastDirKey,DCF_DIR_NAME);
if(sf_is_directory_empty(sTmp))
{
MLOGD("Will Delete Dir:%s\n", sTmp);
remove(sTmp);
system("sync");
}
gLastDirKey = i;
MLOGD("DirKey:%d,FileKey:%d\n", gLastDirKey, gLastFileKey);
return 0;