VC从文件全路径中获取文件名和扩展名方法(CString)_随墨流 (转)
http://wsyjwps1983.blog.163.com/blog/static/68009001200982303713845/
2009-09-23 12:37:13| 分类: OPENCV
|字号
订阅
VC从文件全路径中获取文件名和扩展名方法(CString)(2009-08-05 11:08:15)
方法一:
CString CPrintImage::GetFileTitleFromFileName
(CString FileName,CString& ExtendName) //获取文件名和扩展名
{
int Where;
Where=FileName.ReverseFind('\\');
if(Where==-1)
{
Where=FileName.ReverseFind('/');
}
CString FileTitle=FileName.Right(FileName.GetLength()-1-Where);
int Which=FileTitle.ReverseFind('.');
ExtendName=FileTitle.Right(FileTitle.GetLength()-Which-1);
if (Which!=-1)
{
FileTitle=FileTitle.Left(Which);
}
return FileTitle;
}
调用方法:
CString a,b,c;
a="c:\\kele8\\shootman2\\vision\\123.exe";
b=this->GetFileTitleFromFileName
(a,c);
AfxMessageBox(b); //弹出123.exe
AfxMessageBox(c); //弹出exe
方法二:
CString CPrintImage::GetFileTitleFromFileName
(CString FileName, BOOL Ext)
{
int Where;
Where = FileName.ReverseFind('\\');
if (Where == -1)
Where = FileName.ReverseFind('/');
CString FileTitle = FileName.Right(FileName.GetLength() - 1 - Where);
if (!Ext)
{
int Which = FileTitle.ReverseFind('.');
if (Which != -1)
FileTitle = FileTitle.Left(Which);
}
return FileTitle;
}
调用方法:
CString a,b,c;
a="c:\\kele8\\shootman2\\vision\\123.exe";
b=this->GetFileTitleFromFileName
(a,TRUE);
c=this->GetFileTitleFromFileName
(a,FALSE);
AfxMessageBox(b); 弹出123.exe
AfxMessageBox(c); 弹出123