文件读写时注意的细节问题
2009-10-24 16:26
369 查看
目录是否存在检查:
注意,该函数是检查当前目录下是否有该文件 如果想检查其他目录下是否有该文件,则在参数中输入该文件的完整路径即可
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; } |
TCHAR szDir[MAX_PATH] = {NULL};
GetCurrentDirectory(sizeof(szDir)/sizeof(TCHAR), szDir);
LPTSTR lptFileName="TsTestFunction.exe";
LPTSTR lptPath=szDir;
LPTSTR *lptFilePath=&lptFileName;
DWORD dFlag=GetFullPathName(lptFileName,sizeof(szDir)/sizeof
(TCHAR),lptPath,lptFilePath);
// 执行完上述语句,lptFileName、lptPath、lptFilePath将会得到正确结果
}
相关文章推荐
- daemon进程中文件读写注意的一些问题
- 关于使用input type=file 标签上传文件的注意细节(上传文件 无法获取文件 问题)
- python2.7中编码问题以及txt文件读写的注意事项
- Python3 文件读写注意事项(指针问题)
- [置顶]关于使用input type=file 标签上传文件的注意细节(上传文件 无法获取文件 问题)
- 关于标准C文件流读写问题:fopen,fread,fwrite,fclose的一些注意事项
- daemon进程中文件读写注意的一些问题
- Qt打开外部程序和文件夹需要注意的细节(注意QProcess的空格问题,以及打开本地文件时,需要QUrl::fromLocalFile才可以)
- fstream读写文件注意问题
- 写代码注意啊,小的细节都有大的问题
- [C#]解决读写包含汉字的txt文件时乱码的问题
- java文件上传注意的问题
- 关于android里的文件创建及读写问题
- jsp页面中动态添加上传输入项注意的问题:“添加上传文件”按钮的name属性值不能和onclick属性的值相同!!!
- 网站SEO技巧应该注意的一些细节问题 转载
- 关于android里的文件创建及读写问题
- 如何使用C#压缩文件及注意的问题!
- PHP中打开或包含远程文件时要注意的问题
- XML文件读写编码不是UTF-8的问题
- [opencv] 图像旋转180度要注意的细节问题