获取文件路径:
CString strPath;
int n=m_strOriFileName.ReverseFind('\\')+1;
strPath=m_strOriFileName.Left(n);
获取文件名:
CString strFile;
int n=m_strUntFileName.GetLength()-m_strOriFileName.ReverseFind('\\')-1;
strFile=m_strOriFileName.Right(n);
同理,获取文件后缀名则为:
CString strFileType;
int n=m_strUntFileName.GetLength()-m_strOriFileName.ReverseFind('.')-1;
strFileType=m_strOriFileName.Right(n);
CString strPath;
int n=m_strOriFileName.ReverseFind('\\')+1;
strPath=m_strOriFileName.Left(n);
获取文件名:
CString strFile;
int n=m_strUntFileName.GetLength()-m_strOriFileName.ReverseFind('\\')-1;
strFile=m_strOriFileName.Right(n);
同理,获取文件后缀名则为:
CString strFileType;
int n=m_strUntFileName.GetLength()-m_strOriFileName.ReverseFind('.')-1;
strFileType=m_strOriFileName.Right(n);
本文介绍了如何使用C++从完整文件路径中提取文件路径、文件名及文件后缀的方法。通过几个简单实用的代码片段,读者可以快速掌握这一技能,并应用于实际项目中。
3256

被折叠的 条评论
为什么被折叠?



