KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Programatically Retrieving File Extensions on Mac OS
PRODUCT: 4D | VERSION: | PLATFORM: Mac
Published On: May 2, 2003
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Compatibility: Version: 6.7.x , 6.8.x and 2003

On Windows, the file extension can be obtained by executing the command “Document type”. This command returns Windows file extension (1 to 3-character string). However, it doesn’t work in the same manner on the Mac. The command returns MacOS file type (4-character string) instead. If you want to procedurally obtain the file extension on Mac OS, you can use the following method to do so:

` Project Method: Get_FileExtension
` $1 - Filename or path

C_TEXT($0;$1;$documentPath)
C_BOOLEAN($found)
C_LONGINT($last)
$documentPath:=$1
$found:=False
$last:=Length($documentPath)

Repeat
 If (($documentPath[[$last]]=".") | ($documentPath[[$last]]=":"))
  $found:=True
 Else
  $last:=$last-1
 End if
Until (($found) & ($last>0))

If ($documentPath[[$last]]=".")
 $0:=Delete string($documentPath;1;$last-1)
Else
 $0:=""
End if