最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
对文件操作的一些方法
时间:2022-07-02 11:04:22 编辑:袖梨 来源:一聚教程网
1.获取执行文件的路径
用函数GetModuleFileName
2.获取执行文件所在目录的方法
CString sFile,sPath;
//获取主程序所在路径,存在sPath中
GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer ();
int nPos;
nPos=sPath.ReverseFind ('''');
sPath=sPath.Left (nPos);
sFile = sPath + ; // 将被读取的文件名
3.判断文件是否存在的几种方法
BOOL CPubFunc::FileExist(CString FileName)
{
CFileFind fFind;
return fFind.FindFile(FileName);
}
BOOL CPubFunc::DirectoryExist(CString Path)
{
WIN32_FIND_DATA fd;
BOOL ret = FALSE;
HANDLE hFind = FindFirstFile(Path, &fd);
if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
//目录存在
ret = TRUE;
}
FindClose(hFind);
return ret;
}
BOOL CPubFunc::CreateDirectory(CString path)
{
SECURITY_ATTRIBUTES attrib;
attrib.bInheritHandle = FALSE;
attrib.lpSecurityDescriptor = NULL;
attrib.nLength = sizeof(SECURITY_ATTRIBUTES);
return ::CreateDirectory( path, &attrib);
}
相关文章
- 修真无限轮回手游轮回世界探索攻略修真无限轮回手游深度轮回机制解析 09-02
- 遮天帝路争锋星空古路探索与通关全流程攻略 09-02
- 末日安全屋血狼势力通关攻略|全阶段任务流程与关键决策指南 09-02
- 末日安全屋晶核快速获取攻略末日安全屋高效刷取晶核的实用做法 09-02
- TPLINK TLWR842+ 无线路由器网速限制设置指南 09-02
- 剑星卢瓦高层全收集如何跑图 09-02