#include <dirent.h>
int EmptyDir(char *destDir)
{
DIR *dp;
struct dirent *entry;
struct stat statbuf;
if ((dp = opendir(destDir)) == NULL)
{
mkdir(destDir, 0777);
if ((dp = opendir(destDir)) == NULL)
{
printf("opendir error\n");
return -1;
}
}
if(0 != chdir(destDir))
{
printf("chdir error\n");
return -1;
}
while ((entry = readdir(dp)) != NULL)
{
lstat(entry->d_name, &statbuf);
if (S_ISREG(statbuf.st_mode))
{
remove(entry->d_name);
}
}
return 1;
}