1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
BOOL EmptyDirectory(const char *szRep)
{
WIN32_FIND_DATA FindFileData;
char path[MAX_PATH];
{
CString str;
str=szRep;
if(str.Right(1)!="\\") str+="\\";
str+="*.*";
strcpy(path,str);
}
HANDLE hFind = FindFirstFile(path, &FindFileData);
if (hFind==INVALID_HANDLE_VALUE) return FALSE;
if (strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
strcpy(path,szRep);
strcat(path,"\\");
strcat(path,FindFileData.cFileName);
EmptyDirectory(path);
}
DWORD a = 0;
while (a != ERROR_NO_MORE_FILES)
{
if (!FindNextFile(hFind, &FindFileData))
a = GetLastError();
else
{
if (strcmp(FindFileData.cFileName,".")!=0 && strcmp(FindFileData.cFileName,"..")!=0)
{
strcpy(path,szRep);
strcat(path,"\\");
strcat(path,FindFileData.cFileName);
if (FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
EmptyDirectory(path);
RemoveDirectory(path);
}
else
{
SetFileAttributes(path,FILE_ATTRIBUTE_NORMAL);
DeleteFile(path);
}
}
}
}
FindClose(hFind);
return TRUE;
} |
Partager