GetFileName

 

Description

Extracts the file name part without the path from a string of full path file name.

Syntax

string GetFileName( LPCSTR lpcszFullPathFileName, BOOL bRemoveExt = FALSE )

Parameters

lpcszFullPathFileName
[input] Pointer to a string containing a files full path name.
bRemoveExt
[input] TRUE will remove file extension so only the file name part will be returned

Return

A string containing only the file name with extension or not depending on bRemoveExt.

Examples

EX1

// This is a self contained sample program for the function GetFileName, 
// To run the program, enter the following command in the Script window:
//    GetFileName_ex1
// When you run this program, the following meassages will be printed out:
//   GetFileName done (RemoveExt Flag:OFF(default)): "c:\c\test.dat" => "test.dat"
//   GetFileName done (RemoveExt Flag:ON): "c:\c\test.dat" => "test"
//
void    GetFileName_ex1()
{
    string    strOnlyFileName;        
    string    strFullPathFileName = "c:\\c\\test.dat";
    
    strOnlyFileName = GetFileName(strFullPathFileName);
    printf("  GetFileName done (RemoveExt Flag:OFF(default)): \"%s\" => \"%s\"\n",
      strFullPathFileName,strOnlyFileName);
      
    strOnlyFileName = GetFileName(strFullPathFileName,TRUE);
    printf("  GetFileName done (RemoveExt Flag:ON): \"%s\" => \"%s\"\n",
      strFullPathFileName,strOnlyFileName);
}

Remark

See Also

header to Include

origin.h

Reference