如何从完整的文件路径中分离文件名和路径名?
从路径中分离文件名:
CString GetFileName(CString pathname)
{
for( int i=pathname.GetLength()-1; i>=0; i-- )
{
if( pathname[i]=='\\' )
break;
}
return pathname.Mid( i+1 );
}
从路径中分离路径名(去除文件名):
CString GetPath(CString pathname)
{
int i = 0, j;
while( i<pathname.GetLength() )
{
if( pathname[i]=='\\' )
j = i;
i++;
}
return pathname.Left( j+1 );
}
CString GetFileName(CString pathname)
{
for( int i=pathname.GetLength()-1; i>=0; i-- )
{
if( pathname[i]=='\\' )
break;
}
return pathname.Mid( i+1 );
}
从路径中分离路径名(去除文件名):
CString GetPath(CString pathname)
{
int i = 0, j;
while( i<pathname.GetLength() )
{
if( pathname[i]=='\\' )
j = i;
i++;
}
return pathname.Left( j+1 );
}