void GetFileTitlesFromFilePath(CString strFilePathName,CString& strFullFileName, CString& strFileName, CString& ExtendName) //获取文件名和扩展名
{
int Where;
Where=strFilePathName.ReverseFind('\\');
if(Where==-1)
{
Where=strFilePathName.ReverseFind('/');
}
strFullFileName = strFilePathName.Right(strFilePathName.GetLength()-1-Where);
int Which = strFullFileName.ReverseFind('.');
ExtendName = strFullFileName.Right(strFullFileName.GetLength()-Which-1);
strFileName = strFullFileName.Left(Which);
}
调用示例:
如:“E:\新建 文本文档.txt”
CString strFilePath = "E:\新建 文本文档.txt";CString strFullFileName;
CString strFileName;
CString strFileType;
GetFileTitlesFromFilePath(strFilePath, strFullFileName, strFileName, strFileType);
此时:strFullFileName:"新建 文本文档.txt"
strFileName:"新建 文本文档"
strFileType:"txt"