This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||
|
4D v19.8
File and folder object pathnames
|
filesystem | Designates |
"/RESOURCES" | Current database resources folder |
"/DATA" | Current data folder |
"/PACKAGE" | Database folder (with or without 4dbase extension) |
"/LOGS" | Logs folder of the database |
Note: In some cases, the current database resources folder can be resolved as "/SOURCES" and the database folder can be resolved as "/PROJECT". It does not change the actual filesystem target.
The POSIX syntax is supported on all platforms. POSIX syntax is recommended since it is the most flexible. It is used by default (returned by file.path and folder.path properties).
With this syntax:
In POSIX syntax, you will generally use "filesystem" pathnames with File and Folder commands, for example:
$pathFile:=File("/DATA/Archives/file 2.txt")
$pathFolder:=Folder("/RESOURCES/Pictures")
Platform-specific syntax depends on the operating system on which the command is executed. Note that when creating a file or folder object with this syntax, you must declare it using the fk platform path constant as parameter.
Windows
The following patterns are supported:
Examples with Folder:
$myFolder:=Folder("C:\\Monday";fk platform path).create()
$myFolder:=Folder("\\\\svr-internal\\tempo";fk platform path).create()
Note: See the Entering Windows pathnames and escape sequences paragraph for information about the double "\\'.
macOS
The following patterns are supported (HFS+ syntax):
Examples with Folder:
$myFolder:=Folder("macintosh hd:";fk platform path).create()
$myFolder:=Folder("Monday:Tuesday";fk platform path).create() //a volume must be called Monday
File and Folder constructors
File and Folder commands only accept absolute pathnames. Relative pathnames are not supported and will return errors. For example, the following code is not allowed:
//ERROR
$myFolder:=Folder("myFolder").create() //relative pathname with constructor
If you want to handle files or folders in various locations (database folder, system folders, etc.), you can use filesystems (see above). For example, you can write:
$myFolder:=Folder("/PACKAGE";"myFolder").create() //folder created at the .4db level
$myFile:=File("/DATA/Prefs/tempo.txt").create() //file created in the data folder
.file() and .folder() folder methods
Methods of file and folder objects such as folder.file( ) and folder.folder( ) expect relative POSIX pathnames. For example:
//to reference a "Picture" folder within the user documents folder
$userImages:=Folder(fk documents folder).folder("Pictures")
//to create a folder on the desktop
$myFolder2:=Folder(fk desktop folder).folder("myFolder").create()
Absolute pathnames are not supported and will return errors.
The flexibility of commands and methods of this theme, combined with object notation, offers you various possibilities for handling files and folders, like in the following examples:
$f:=Folder(fk desktop folder).folder("archive/jan2019")
$f2:=Folder("/DATA/archive/jan2019").file("total.txt")
$f3:=Folder("/DATA/archive/jan2019")
$f4:=File("/DATA/info.txt")
$f5:=File("c:\\archives\\local\\jan2019.txt";fk platform path)
$f6:=File(fk backup log file)
Product: 4D
Theme: File and Folder
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)