MFC 文件及其属性相关操作 (MFC 文件操作 三)
2011-07-30 18:05
507 查看
一、 从路径中 提取扩展名
view plaincopy to clipboardprint?
CString path("C:/ForVcTest/diary.txt");
CString ext = path.Mid(path.ReverseFind('.')+1);
AfxMessageBox(ext);
三、获取文件属性
view plaincopy to clipboardprint?
DWORD dwAttr = GetFileAttributes("C:/ForVcTest/2.txt");//获取文件的属性
if (dwAttr == FILE_ATTRIBUTE_ARCHIVE){
AfxMessageBox("FILE_ATTRIBUTE_ARCHIVE");
}
五、获取当前程序所在路径
view plaincopy to clipboardprint?
//提取文件路径
char appName[_MAX_PATH];
GetModuleFileName(NULL,appName,_MAX_PATH);
CString szPath(appName);
AfxMessageBox(szPath);
移动后 源文件被删除,目标文件被创建
七、Path Name Title 的区别
view plaincopy to clipboardprint?
CFile file("C:/ForVcTest/newCopy.txt",CFile::modeRead);
CString szPath = file.GetFilePath();
CString szName = file.GetFileName();
CString szTitle = file.GetFileTitle();
AfxMessageBox("szPath = "+szPath);
AfxMessageBox("szName = "+szName);
AfxMessageBox("szTitle = "+szTitle);
view plaincopy to clipboardprint?
CString path("C:/ForVcTest/diary.txt");
CString ext = path.Mid(path.ReverseFind('.')+1);
AfxMessageBox(ext);
view plaincopy to clipboardprint? CString path("C:/ForVcTest/diary.txt"); CString name = path.Mid(path.ReverseFind('/')+1); AfxMessageBox(name); CString path("C:/ForVcTest/diary.txt"); CString name = path.Mid(path.ReverseFind('/')+1); AfxMessageBox(name);
三、获取文件属性
view plaincopy to clipboardprint?
DWORD dwAttr = GetFileAttributes("C:/ForVcTest/2.txt");//获取文件的属性
if (dwAttr == FILE_ATTRIBUTE_ARCHIVE){
AfxMessageBox("FILE_ATTRIBUTE_ARCHIVE");
}
view plaincopy to clipboardprint? SetFileAttributes("C:/ForVcTest/2.txt",FILE_ATTRIBUTE_READONLY);//|FILE_ATTRIBUTE_HIDDEN SetFileAttributes("C:/ForVcTest/2.txt",FILE_ATTRIBUTE_READONLY);//|FILE_ATTRIBUTE_HIDDEN
五、获取当前程序所在路径
view plaincopy to clipboardprint?
//提取文件路径
char appName[_MAX_PATH];
GetModuleFileName(NULL,appName,_MAX_PATH);
CString szPath(appName);
AfxMessageBox(szPath);
view plaincopy to clipboardprint? MoveFile("C:/ForVcTest/diary.txt","C:/ForVcTest/newCopy.txt"); MoveFile("C:/ForVcTest/diary.txt","C:/ForVcTest/newCopy.txt");
移动后 源文件被删除,目标文件被创建
七、Path Name Title 的区别
view plaincopy to clipboardprint?
CFile file("C:/ForVcTest/newCopy.txt",CFile::modeRead);
CString szPath = file.GetFilePath();
CString szName = file.GetFileName();
CString szTitle = file.GetFileTitle();
AfxMessageBox("szPath = "+szPath);
AfxMessageBox("szName = "+szName);
AfxMessageBox("szTitle = "+szTitle);
view plaincopy to clipboardprint? bool SplitFile() { //文件分割 CFile m_File; CString m_FileName,m_FileTitle,m_FilePath; m_FilePath = "C://ForVcTest//newCopy.txt"; char pBuf[40]; if(m_File.Open(m_FilePath,CFile::modeRead | CFile::shareDenyWrite)) { m_FileName=m_File.GetFileName(); m_FileTitle=m_File.GetFileTitle(); // DWORD FileLength=m_File.GetLength(); // DWORD PartLength=FileLength/2+FileLength%2; int nCount=1; CString strName; CFile wrFile; DWORD ReadBytes; while(true) { ReadBytes=m_File.Read(pBuf,40); //ReadBytes 实际读取的字节数 strName.Format("C://ForVcTest//%s%d.txt",m_FileTitle,nCount); wrFile.Open(strName,CFile::modeWrite | CFile::modeCreate); wrFile.Write(pBuf,ReadBytes); wrFile.Close(); if(ReadBytes<40) //实际读取的字节数 不足 分配的大小,则说明文件读完了 break; nCount++; } m_File.Close(); } else{ AfxMessageBox("不能打开文件"); return fasle; } return true; } bool SplitFile() { //文件分割 CFile m_File; CString m_FileName,m_FileTitle,m_FilePath; m_FilePath = "C://ForVcTest//newCopy.txt"; char pBuf[40]; if(m_File.Open(m_FilePath,CFile::modeRead | CFile::shareDenyWrite)) { m_FileName=m_File.GetFileName(); m_FileTitle=m_File.GetFileTitle(); // DWORD FileLength=m_File.GetLength(); // DWORD PartLength=FileLength/2+FileLength%2; int nCount=1; CString strName; CFile wrFile; DWORD ReadBytes; while(true) { ReadBytes=m_File.Read(pBuf,40); //ReadBytes 实际读取的字节数 strName.Format("C://ForVcTest//%s%d.txt",m_FileTitle,nCount); wrFile.Open(strName,CFile::modeWrite | CFile::modeCreate); wrFile.Write(pBuf,ReadBytes); wrFile.Close(); if(ReadBytes<40) //实际读取的字节数 不足 分配的大小,则说明文件读完了 break; nCount++; } m_File.Close(); } else{ AfxMessageBox("不能打开文件"); return fasle; } return true; }
相关文章推荐
- MFC 文件及其属性相关操作 (MFC 文件操作 三)
- MFC 文件及其属性相关操作 (MFC 文件操作 三)
- MFC文件操作相关
- iOS文件的操作与相关的属性
- rhel6文件系统属性更改相关操作
- Linux和Windows下文件和目录的相关属性及操作
- MFC读写文件相关操作
- MFC个人笔记--创建属性表,并通过文件操作,保存属性表中用户的选择 的步骤
- MFC个人笔记--创建属性表,并通过文件操作,保存属性表中用户的选择 的步骤
- Krpano学习:在C#中修改全景场景属性(C#操作全景vtour.xml文件及相关瓦片数据/panos/*.tiles)
- IOS文件系统及其相关操作(NSFileManager,NSFileHandle)
- MFC 相关文件夹、文件操作
- 获取文件的属性信息及其操作函数
- IOS文件系统及其相关操作(NSFileManager,NSFileHandle)
- MFC 文件与文件夹相关操作
- linux下的文件IO缓冲区,及其相关操作
- MFC 文件与文件夹相关操作
- Properties的用法及其操作属性文件(遍历Key)
- <MFC笔记>BMP位图文件的格式及其操作
- MFC的文件操作及其序列化