KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use Folder Separator constant to ensure paths work on both Mac and Windows
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: October 17, 2022

If your code contains any hardcoded paths to a folder or file, it is important to ensure that this path can work between Mac and Windows operating systems. The key difference between the two path formats is the directory separator at the end of folder names: “\\” for Windows and “:” for Mac.

This is especially important for certain commands, such as READ PICTURE FILE or DOCUMENT TO TEXT, where 4D code reads a file on the machine’s hard drive and needs the path to be in the correct system format.

To ensure the correct format based on the operating system is used, your path should use the “Folder separator” constant after each folder name. You can check this constant by going to the Explorer window > Constants > System Documents > Folder separator.

Example: Path to a .txt file

$path:=Get 4D folder(Database folder)+"SampleFolder"+Folder separator+"TextDocuments"+Folder separator+"SampleText.txt"


On Mac:
Macintosh HD:Users:User:Documents:Sample4DProject:SampleFolder:TextDocuments:SampleText.txt


On Windows:
C:\\Users\\User\\Documents\\Sample4DProject\\SampleFolder\\TextDocuments\\SampleText.txt