Chinaunix首页 | 论坛 | 博客
  • 博客访问: 408973
  • 博文数量: 78
  • 博客积分: 3642
  • 博客等级: 中校
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-23 15:33
文章分类

全部博文(78)

文章存档

2007年(53)

2006年(25)

分类: C/C++

2007-04-13 14:12:14

BOOL DeleteDirectory(LPCTSTR lpszPath)
{
    WIN32_FIND_DATA FindData;
    HANDLE hFile;
    TCHAR szFile[MAX_PATH];
    TCHAR szFullName[MAX_PATH];
    BOOL bReturn = TRUE;

    if(IsDirectory(lpszPath))
    {

        //You can use _sntprintf.
        sntprintf(szFile,MAX_PATH,_T("%s\\*"),lpszPath);
        hFile = FindFirstFile(szFile,&FindData);
        if(hFile == INVALID_HANDLE_VALUE)
        {
            bReturn = FALSE;
        }
        else
        {
            do
            {
                if(_tcscmp(FindData.cFileName, _T(".")) == 0 ||
                   _tcscmp(FindData.cFileName, _T("..")) == 0 )
                {
                    continue;
                }
                //absolute path.
                sntprintf(szFullName,MAX_PATH,_T("%s\\%s"),lpszPath,FindData.cFileName);
                if(!DeleteDirectory(szFullName))
                {
                    bReturn = FALSE;
                }
            } while(FindNextFile(hFile,&FindData));
            FindClose(hFile);
        }
    }
    //HKLM\SYSTEM\CurrentControlSet\Control\SessionManager\PendingFileRenameOperations
    if(!MoveFileEx(lpszPath,NULL,MOVEFILE_DELAY_UNTIL_REBOOT))
    {
        bReturn = FALSE;
    }
    return bReturn;
}
BOOL IsDirectory(LPCTSTR lpszPath)
{
    DWORD dwAttribute;
    dwAttribute = GetFileAttributes(lpszPath);
    if(dwAttribute == 0xffffffff)
    {
        return FALSE;
    }
    return (dwAttribute & FILE_ATTRIBUTE_DIRECTORY);
}

阅读(2392) | 评论(0) | 转发(0) |
0

上一篇:厦门的雨季

下一篇:字符的趣事

给主人留下些什么吧!~~