VC中判断目录,文件是否存在,创建目录,求目录或文件大小的方法
http://blog.163.com/xue_huashan/blog/static/8044800420096109544768/
目录是否存在检查:
文件存在性检查: 注意,该函数是检查当前目录下是否有该文件 如果想检查其他目录下是否有该文件,则在参数中输入该文件的完整路径即可
创建目录:
文件大小: 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; } |