Tech Tip: Utility method to get the file name of a given file path
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: June 11, 2013
Developers may have a full file path, but only wish to display the name of the file. To do this the following utility method can be used:
// ---------------------------------------------------- // Method: UTIL_get_file_name // Description // Returns the file name from a given file path // // Parameters // $1 (Text) - Path to file // // $0 (Text) - File name // // ---------------------------------------------------- C_TEXT($1;$filePath_t) C_TEXT($0) C_LONGINT($pos_l) $filePath_t:=$1 $pos_l:=Position(Folder separator;$filePath_t) While ($pos_l#0) $filePath_t:=Delete string($filePath_t;1;$pos_l) $pos_l:=Position(Folder separator;$filePath_t) End while $0:=$filePath_t |
The above method takes in a full file path and returns just the file name. Here is an example of how the method can be called:
C_TEXT($fileName_t;$filePath_t) $filePath_t:="Macintosh HD:Users:admin:Desktop:testFolder:test.txt" $fileName_t:=UTIL_get_file_name ($filePath_t) //$fileName will contain the value "test.txt" |