Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7194022
  • 博文数量: 510
  • 博客积分: 12019
  • 博客等级: 上将
  • 技术积分: 6836
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-01 16:46
文章分类

全部博文(510)

文章存档

2022年(2)

2021年(6)

2020年(59)

2019年(4)

2018年(10)

2017年(5)

2016年(2)

2015年(4)

2014年(4)

2013年(16)

2012年(47)

2011年(65)

2010年(46)

2009年(34)

2008年(52)

2007年(52)

2006年(80)

2005年(22)

分类: C/C++

2007-10-29 11:21:49

//删除目录下所有文件,目录不删除
bool KbaseToXml::DeleteDirectoryFiles(char* sDirName)
{
    CFileFind tempFind;
    char sTempFileFind[200] ;

    sprintf(sTempFileFind,"%s\\*.*",sDirName);
    BOOL IsFinded = tempFind.FindFile(sTempFileFind);
    while (IsFinded)
    {
        IsFinded = tempFind.FindNextFile();

        if (!tempFind.IsDots())
        {
            char sFoundFileName[200];
            strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));

            if (tempFind.IsDirectory())
            {
                char sTempDir[200];
                sprintf(sTempDir,"%s\\%s",sDirName,sFoundFileName);
                DeleteDirectoryFiles(sTempDir);
            }
            else
            {
                char sTempFileName[200];
                sprintf(sTempFileName,"%s\\%s",sDirName,sFoundFileName);
                DeleteFile(sTempFileName);
            }
        }
    }
    tempFind.Close();
    /*if(!RemoveDirectory(sDirName))
    {
    return FALSE;
    } */
return TRUE;
}



//删除目录下所有文件,目录同时删除
bool KbaseToXml::DeleteDirectory(char* sDirName)
{
    CFileFind tempFind;
    char sTempFileFind[200] ;

    sprintf(sTempFileFind,"%s\\*.*",sDirName);
    BOOL IsFinded = tempFind.FindFile(sTempFileFind);
    while (IsFinded)
    {
        IsFinded = tempFind.FindNextFile();

        if (!tempFind.IsDots())
        {
            char sFoundFileName[200];
            strcpy(sFoundFileName,tempFind.GetFileName().GetBuffer(200));

            if (tempFind.IsDirectory())
            {
                char sTempDir[200];
                sprintf(sTempDir,"%s\\%s",sDirName,sFoundFileName);
                DeleteDirectory(sTempDir);
            }
            else
            {
                char sTempFileName[200];
                sprintf(sTempFileName,"%s\\%s",sDirName,sFoundFileName);
                DeleteFile(sTempFileName);
            }
        }
    }
    tempFind.Close();
    if(!RemoveDirectory(sDirName))
    {
    return FALSE;
    }
return TRUE;

阅读(4494) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~