VC中判断目录,文件是否存在,创建目录,求目录或文件大小的方法
2008-09-11 17:09
941 查看
目录是否存在检查:
文件存在性检查:
注意,该函数是检查当前目录下是否有该文件
如果想检查其他目录下是否有该文件,则在参数中输入该文件的完整路径即可
创建目录:
文件大小:
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;
}
BOOL FolderExist(CString strPath) { WIN32_FIND_DATA wfd; BOOL rValue = FALSE; HANDLE hFind = FindFirstFile(strPath, &wfd); if ((hFind!=INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)) { rValue = TRUE; } FindClose(hFind); return rValue; } |
注意,该函数是检查当前目录下是否有该文件
如果想检查其他目录下是否有该文件,则在参数中输入该文件的完整路径即可
BOOL FileExist(CString strFileName) { CFileFind fFind; return fFind.FindFile(strFileName); } |
BOOL CreateFolder(CString strPath) { SECURITY_ATTRIBUTES attrib; attrib.bInheritHandle = FALSE; attrib.lpSecurityDescriptor = NULL; attrib.nLength = sizeof(SECURITY_ATTRIBUTES); //上面定义的属性可以省略 //直接使用return ::CreateDirectory(path, NULL);即可 return ::CreateDirectory(strPath, &attrib); } |
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;
}
相关文章推荐
- VC中判断目录,文件是否存在,创建目录,求目录或文件大小的方法
- VC中判断目录,文件是否存在,创建目录,求目录或文件大小的方法
- VC中判断目录,文件是否存在,创建目录,求目录或文件大小的方法
- VC中判断目录,文件是否存在,创建目录的方法
- VC中判断目录,文件是否存在,创建目录的方法
- VC中判断目录,文件是否存在,创建目录的方法
- VC中判断目录,文件是否存在,创建目录的方法
- VC 判断目录/文件是否存在 创建目录 求目录/文件大小
- VC中判断目录,文件是否存在,创建目录的方法
- VC中判断目录,文件是否存在,创建目录的方法
- VC中判断目录,文件是否存在,创建目录的方法
- VC中判断目录,文件是否存在,创建目录的方法
- C中判断目录,文件是否存在,创建目录,求目录或文件大小的方法(转)
- VC(MFC)判断文件/目录是否存在,创建目录
- Go语言编程中判断文件是否存在是创建目录的方法
- 详解C++循环创建多级目录及判断目录是否存在的方法
- python 判断目录和文件是否存在,若不存在即创建
- android 获取路径目录方法以及判断目录是否存在,创建目录
- android 获取路径目录方法以及判断目录是否存在,创建目录
- Lua判断一个目录或文件是否存在的方法