先来先卖。

解决方案 »

  1.   

    // 删除目录
    void DeleteDirectory(CString strDir)
    {
    if(strDir.IsEmpty()) {
                      RemoveDirectory(strDir);
    return;
             }
    // 首先删除文件及子文件夹
    CFileFind ff;
    BOOL bFound = ff.FindFile(strDir+"\\*", 0);
    while(bFound)
    {
    bFound = ff.FindNextFile();
    if(ff.GetFileName()=="."||ff.GetFileName()=="..")
    continue;
    // 去掉文件(夹)只读等属性
    SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL);
    if(ff.IsDirectory()) { // 递归删除子文件夹
    DeleteDirectory(ff.GetFilePath());
    RemoveDirectory(ff.GetFilePath());
    }
    else {
    DeleteFile(ff.GetFilePath()); // 删除文件
    }
    }
    ff.Close();
    // 然后删除该文件夹
    RemoveDirectory(strDir);
    }
      

  2.   

    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;
    char szFind[MAX_PATH];
    char szTempDir[MAX_PATH]; sprintf(szFind,"%s\\*.*",lpPathName);
    hFind = FindFirstFile(szFind, &FindFileData);
    if (hFind == INVALID_HANDLE_VALUE)
    {
    FindClose(hFind);
    return FALSE;
    }
    do
    {
    if (strcmp(FindFileData.cFileName,".")==0
    || strcmp(FindFileData.cFileName,"..")==0)
    {
    continue;
    }
    sprintf(szTempDir,"%s\\%s",lpPathName,FindFileData.cFileName);
    }
    while(FindNextFile(hFind,&FindFileData));
    FindClose(hFind);
      

  3.   

    void Exp(const char * name);int main(int argc, char* argv[])
    {
    Exp("c:\\windows");
    return 0;
    }
    void Exp(const char * name)
    {
    if(!name)
    {
    return ;
    }
    if(!strlen(name))
    {
    return ;
    } char szBuf[MAX_PATH] = {0};
    strcpy(szBuf , name);
    if(szBuf[strlen(szBuf) - 1] != '\\')
    {
    strcat(szBuf , "\\");
    } strcat(szBuf , "*.*"); WIN32_FIND_DATA fd;
    memset(&fd , 0 , sizeof(fd)); BOOL bFind = TRUE;
    HANDLE hFind = FindFirstFile(szBuf , &fd);
    while(bFind)
    {
    if(strcmp(fd.cFileName , ".") == 0)
    {
    bFind = FindNextFile(hFind , &fd);
    continue;
    }
    else if(strcmp(fd.cFileName , "..") == 0)
    {
    bFind = FindNextFile(hFind , &fd);
    continue;
    }
    else if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    char szPath[MAX_PATH] = {0};
    strcpy(szPath , szBuf);
    *strrchr(szPath , '\\') = '\0';
    strcat(szPath , "\\");
    strcat(szPath , fd.cFileName);
    Exp(szPath);
    }
    else
    {
    char szPath[MAX_PATH] = {0};
    strcpy(szPath , szBuf);
    *strrchr(szPath , '\\') = '\0';
    strcat(szPath , "\\");
    strcat(szPath , fd.cFileName);
    printf("%s\n" , szPath);
    }
    bFind = FindNextFile(hFind , &fd);
    } CloseFind(hFind);
    return ;
    }