VC下没有直接的删除文件夹的函数, 下面的函数展示了如何删除整个文件夹:
void DeleteDir(LPCTSTR lpszDir)
{
WIN32_FIND_DATA wfd;
TCHAR szFile[MAX_PATH];
TCHAR szDelDir[MAX_PATH];
lstrcpy(szDelDir, lpszDir);
wsprintf(szFile, TEXT("%s\\*.*"), lpszDir);
HANDLE hFindFile = FindFirstFile(szFile, &wfd);
if ( INVALID_HANDLE_VALUE == hFindFile )
return;
BOOL bFind = TRUE;
while ( bFind )
{
bFind = FindNextFile(hFindFile, &wfd);
if ( lstrcmpi(wfd.cFileName, TEXT(".")) == 0 ||
lstrcmpi(wfd.cFileName, TEXT("..")) == 0 )
continue;
wsprintf(szFile, TEXT("%s\\%s"), szDelDir, wfd.cFileName);
if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
DeleteDir(szFile);
else
DeleteFile(szFile);
}
FindClose(hFindFile);
RemoveDirectory(szDelDir);
}
|
author: thinkere-mail:
cnhnyugmail.comqq: 94483026
阅读(1524) | 评论(0) | 转发(0) |