急!求删除目录及目录下的所有文件 wince
大家好!我想了各种办法想删除目录下的所有文件,怎么都不成功,网上的两种办法都试过了
一、包含了头文件#include "shellapi.h"
BOOL CsystemDlg::DelTree(LPCTSTR lpszPath)
{
SHFILEOPSTRUCT FileOp;
FileOp.fFlags = FOF_NOCONFIRMATION;
FileOp.hNameMappings = NULL;
FileOp.hwnd = NULL;
FileOp.lpszProgressTitle = NULL;
FileOp.pFrom = lpszPath;
FileOp.pTo = NULL;
FileOp.wFunc = FO_DELETE;
return ::SHFileOperationW(&FileOp)==0;
}
运行结果:
无法解析的外部符号 SHFileOperationW,该符号在函数 "public: int __cdecl CsystemDlg::DelTree(wchar_t const *)" (?DelTree@CsystemDlg@@QAAHPB_W@Z) 中被引用
二、
CString strDir = L"\\NandFlash\\2";
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);
}
运行结果:
1>.\systemDlg.cpp(1838) : error C2065: 'CFileFind' : undeclared identifier