1.创建一个文件夹
CreateDirectory(只能创建一层目录)
2.文件夹的删除
RemoveDirectory(此函数只能删除一个空的目录,如果目录中有子目录或子文件的话会删除失败的)
3.文件夹属性的获取
GetFileAttributes
4.文件和文件夹的遍历操作
CFileFind
实现删除非空目录
bool deleteTargetFolder(LPCTSTR lpstrPath)
{
CString strRootPath(lpstrPath);
if (strRootPath[strRootPath.GetLength() - 1] != '\\')
{
strRootPath += _T("\\");
}
CFileFind mFinder;
bool bFind = mFinder.FindFile(strRootPath + _T("*.*"));//如果指定类型的话,只能在此处,这里是删除所有的文件
while (bFind)
{
bFind = mFinder.FindNextFileW();
if (mFinder.IsDots())
{
continue;
}
else
{
if (mFinder.IsDirectory())//目标是目录文件夹
{
deleteTargetFolder(mFinder.GetFilePath());
}
else
{
DeleteFile(mFinder.GetFilePath());//目标是文件
}
}
}
mFinder.Close();
RemoveDirectory(strRootPath);
return true;
}