KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Quick File Creation Locations
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: September 27, 2022

When developing on 4D, it can sometimes be helpful to generate a file to test a feature or to output some data for reference. There are many locations available, but the location should be accessible with read and write privledges. The location should also be easily accessible.

There are way access such locations, but below are some quick and easy locations to create and access the files.

1) The System folder command returns the path to the directory type based on the passed parameter. In this scenario, the Desktop or Documents folder would be a good choice. The desktop is always readily available from a file explorer or behind all of the windows. The documents folder is also typically accessible from a file explorer.

TEXT TO DOCUMENT(System folder(Desktop)+"text.txt"; $someText)

2) The current Database's directory is the default location when a full path is not provided. The location of the Database's directory for the developer should be known and accessible. Since this is the default path, code can quickly be written for tests, such as just a file name of "text.txt" instead of needing to place a full path name: System folder(Desktop)+"text.txt".

TEXT TO DOCUMENT("text.txt"; $someText)

3) A more UI based solution would be to utilize the Select document command:
$text:=Select document(""; "*"; ""; File name entry)

The code above will allow the file explorer to be used to navigate to a specific location and select or enter a name of a new file. Then the full path will be contained in the Document system variable and can be used:
TEXT TO DOCUMENT(Document;$someString)

There are various other options available, but the above three are fairly simple and straight forward that can be used to quickly select a destination for a file.