www.pudn.com > pullOut.rar > ApiFileNameStr.cpp
//ApiFileNameStr.cpp
#include "stdafx.h"
#include "ApiFileNameStr.h"
CString WINAPI GetFileExtByPath(CString strPath)
{
CString ext;
int len=strPath.GetLength();
int pos=strPath.ReverseFind('.');
if(-1!=pos)
ext=strPath.Right(len-pos-1);
else
ext=_T("");
return ext;
}
CString WINAPI GetFileTitleByPath(CString PathName)
{
CString filename=GetFileNameByPath(PathName);
return GetFileTitleByName(filename);
}
CString WINAPI MakePathName(CString Folder,CString Title,CString Ext)
{
CString pathname;
if(Folder==_T(""))
{
pathname=Title+_T(".");
pathname+=Ext;
}
else
{
int len=Folder.GetLength();
if(Folder.GetAt(len-1)=='\\') pathname=Folder+_T("\\");
else pathname=Folder;
pathname+=Title;
pathname+=Ext;
}
return pathname;
}
CString WINAPI GetFileTitleByName(CString FileName)
{
CString Target;
int pos=FileName.ReverseFind('.');
if(-1==pos) Target=FileName;
else
Target=FileName.Left(pos);
return Target;
}
CString WINAPI NameTargetFile(CString source,CString newExt)
{
CString Target;
CString ext=_T(".");
ext+=newExt;
int pos=source.ReverseFind('.');
if(-1==pos) Target=source+ext;
else
{
CString TmpStr=source.Left(pos);
Target=TmpStr+ext;
}
return Target;
}
void WINAPI ReArrangePathStr(CString &strPath)
{
// this means we have an invalid path that looks like
// "C:\\foo.bmp"
// We need to cut out the extra slash
if (strPath.Find(":\\\\") == 1 && strPath.GetLength() > 4)
{
CString temp;
temp = strPath.Left(3);
temp += strPath.Mid(4);
strPath = temp;
}
}
CString WINAPI GetFileNameByPath(CString PathName)
{
int len=PathName.GetLength();
int pos=PathName.ReverseFind('\\');
if(-1!=pos)
{
CString retStr=PathName.Right(len-pos-1);
return retStr;
}
else
{
AfxMessageBox("Wrong in FilePath!");
return _T("");
}
}
CString WINAPI GetFileFolderByPath(CString PathName)
{
int len=PathName.GetLength();
int pos=PathName.ReverseFind('\\');
if(-1!=pos)
{
CString retStr=PathName.Left(pos+1);
return retStr;
}
else
{
AfxMessageBox("Wrong in FilePath!");
return _T("");
}
}
CString WINAPI GetFilePrefixByTitle(CString FileTitle)
{
int len=FileTitle.GetLength();
char ch;
int pos=-1;
for(int i=len-1;i>=0;i--)
{
ch=FileTitle.GetAt(i);
if(ch>='0'&&ch<='9');
else
{
pos=i;
break;
}
}
if(pos<=0)return _T("");
CString Prefix=FileTitle.Left(pos+1);
return Prefix;
}
int WINAPI GetNumberFromTitle(CString FileTitle)
{
int len=FileTitle.GetLength();
char ch;
int pos=-1;
for(int i=len-1;i>=0;i--)
{
ch=FileTitle.GetAt(i);
if(ch>='0'&&ch<='9');
else
{
pos=i;
break;
}
}
if(pos<=0)return -1;
CString StrNum=FileTitle.Right(len-pos-1);
int NumLen=StrNum.GetLength();
if (0==NumLen)return -1;
else
{
int number=0;
for(int i=0;i