Skip to content

Instantly share code, notes, and snippets.

@moehuster
Created April 4, 2014 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moehuster/9969426 to your computer and use it in GitHub Desktop.
Save moehuster/9969426 to your computer and use it in GitHub Desktop.
int clean_subdir(TCHAR *szPath)
{
HANDLE hFind;
BOOL bContinue = TRUE;
WIN32_FIND_DATA FindData;
TCHAR szFile[MAX_PATH];
wsprintf(szFile, TEXT("%s\\*"), szPath);
hFind = FindFirstFile(szFile, &FindData);
if (hFind==INVALID_HANDLE_VALUE)
return 0;
while (bContinue){
if (_tcscmp(FindData.cFileName, TEXT("."))&&
_tcscmp(FindData.cFileName, TEXT(".."))){
wsprintf(szFile, TEXT("%s\\%s"), szPath, FindData.cFileName);
if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
func(szFile);
RemoveDirectory(szFile);
}
else{
DWORD dwAttributes = GetFileAttributes(szFile);
dwAttributes &= ~FILE_ATTRIBUTE_READONLY;
SetFileAttributes(szFile, dwAttributes);
DeleteFile(szFile);
}
}
bContinue = FindNextFile(hFind, &FindData);
}
FindClose(hFind);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment