KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Example method to get a filename from a path
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: June 9, 2006
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

The following method will extract a filename from a full path.

For example, if "C:\Windows\run.exe" is passed, method will return "run.exe".

Note: the variable "OSPathBreak" is a process variable that must contain the path separator based on the platform (":" for OS X and "\" for Windows).


C_TEXT($newPath;$path)
C_LONGINT($i;$lengthPath)
C_TEXT($0;$1)

$path:=$1

$newPath:=""
$i:=Length($path)
$lengthPath:=Length($path)

Repeat

  If (Substring($path;$i;1)=OSpathBreak)

    $newPath:=Substring($path;($i+1))

  End if

  $i:=$i-1

Until ($newPath#"")

$0:=$newPath