目录是否存在检查:
BOOL FolderExist(CString strPath) |
文件存在性检查:
注意,该函数是检查当前目录下是否有该文件
如果想检查其他目录下是否有该文件,则在参数中输入该文件的完整路径即可
BOOL FileExist(CString strFileName) |
创建目录:
BOOL CreateFolder(CString strPath) |
文件大小:
DWORD GetFileSize(CString filepath)
{
WIN32_FIND_DATA fileInfo;
HANDLE hFind;
DWORD fileSize;
CString filename;
filename = filepath;
hFind = FindFirstFile(filename,&fileInfo);
if(hFind != INVALID_HANDLE_VALUE)
fileSize = fileInfo.nFileSizeLow;
FindClose(hFind);
return filesize;
}
当然在CFileFind里面有GetLength()函数,也可以求得。
文件夹大小
DWORD CVCTestDlg::GetDirSize(CString strDirPath)
{
CString strFilePath;
DWORD dwDirSize = 0;
strFilePath += strDirPath;
strFilePath += "//*.*";
CFileFind finder;
BOOL bFind = finder.FindFile(strFilePath);
while (bFind)
{
bFind = finder.FindNextFile();
if (!finder.IsDots())
{
CString strTempPath = finder.GetFilePath();
if (!finder.IsDirectory())
{
dwDirSize += finder.GetLength();
}
else
{
dwDirSize += GetDirSize(strTempPath);
}
}
}
finder.Close();
return dwDirSize;
}