KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Extracting pathname from long name
PRODUCT: 4D | VERSION: 2003.2 | PLATFORM: Mac & Win
Published On: April 15, 2004

If you want to programmatically save files at the same directory as the structure or data file of the database you are currently working on, you can do so by using the path name of the structure or data file. The commands 'Structure file' and 'Data file' returns the long name (path name + filename) of the structure and data file respectively as a string. To get the path to their directory, you need to remove the filename of the structure file or data file from the returned string. The method below will extract the pathname from the long name:

` method: extractPathname
C_STRING(100;$var1;$0)
C_INTEGER($separator;$StrPtr)
C_INTEGER($myPlatform;$mySystem;$myMachine)

PLATFORM PROPERTIES($myPlatform;$mySystem;$myMachine)
If ($myPlatform=Windows )  ` check if platform is Windows or Mac
   $separator:=Ascii("\\")
Else
   $separator:=Ascii(":")
End if

$var1:=Data file  ` get the pathname of Datafile. For the structure file use 'Structure file' instead
$StrPtr:=Length($var1)  ` get length of string

While ($var1[[$StrPtr]]#Char($separator))  ` starting from the end of string, find first occurence of the separator
  $StrPtr:=$StrPtr-1
End while
$0:=Substring($var1;1;$StrPtr)