File
File
objects are created with the File
command. They contain references to disk files that may or may not actually exist on disk. For example, when you execute the File
command to create a new file, a valid File
object is created but nothing is actually stored on disk until you call the file.create( )
function.
Example
The following example creates a preferences file in the project folder:
var $created : Boolean
$created:=File("/PACKAGE/SpecialPrefs/"+Current user+".myPrefs").create()
Pathnames
File
objects support several pathnames, including filesystems
or posix
syntax. Supported pathnames are detailed in the Pathnames page.
File object
.copyTo( destinationFolder : 4D.Folder { ; newName : Text } { ; overwrite : Integer } ) : 4D.File copies the File object into the specified destinationFolder |
.create() : Boolean creates a file on disk according to the properties of the File object |
.createAlias( destinationFolder : 4D.Folder ; aliasName : Text { ; aliasType : Integer } ) : 4D.File creates an alias (macOS) or a shortcut (Windows) |
.creationDate : Date the creation date of the file |
.creationTime : Time the creation time of the file |
.delete( ) deletes the file |
.exists : Boolean true if the file exists on disk |
.extension : Text the extension of the file name (if any) |
.fullName : Text the full name of the file, including its extension (if any) |
.getAppInfo() : Object returns the contents of a .exe, .dll or .plist file information as an object |
.getContent( ) : Blobreturns a BLOB containing the entire content of a file |
.getIcon( { size : Integer } ) : Picture the icon of the file |
.getText( { charSetName : Text { ; breakMode : Integer } } ) : Text .getText( { charSetNum : Integer { ; breakMode : Integer } } ) : Text returns the contents of the file as text |
.hidden : Boolean true if the file is set as "hidden" at the system level |
.isAlias : Boolean true if the file is an alias, a shortcut, or a symbolic link |
.isFile : Boolean always true for a file |
.isFolder : Boolean always false for a file |
.isWritable : Boolean true if the file exists on disk and is writable |
.modificationDate : Date the date of the file's last modification |
.modificationTime : Time the time of the file's last modification |
.moveTo( destinationFolder : 4D.Folder { ; newName : Text } ) : 4D.File moves or renames the File object into the specified destinationFolder |
.name : Text the name of the file without extension (if any) |
.original : 4D.File .original : 4D.Folder the target element for an alias, a shortcut, or a symbolic link file |
.parent : 4D.Folder the parent folder object of the file |
.path : Text the POSIX path of the file |
.platformPath : Text the path of the file expressed with the current platform syntax |
.rename( newName : Text ) : 4D.File renames the file with the name you passed in newName and returns the renamed File object |
.setAppInfo( info : Object ) writes the info properties as information contents of a .exe, .dll or .plist file |
.setContent ( content : Blob ) rewrites the entire content of the file using the data stored in the content BLOB |
.setText ( text : Text {; charSetName : Text { ; breakMode : Integer } } ) .setText ( text : Text {; charSetNum : Integer { ; breakMode : Integer } } ) writes text as the new contents of the file |
.size : Real the size of the file expressed in bytes |
File
History
Release | Changes |
---|---|
17 R5 | Added |
File ( path : Text { ; pathType : Integer }{ ; * } ) : 4D.File
File ( fileConstant : Integer { ; * } ) : 4D.File
Parameter | Type | Description | |
---|---|---|---|
path | Text | -> | File path |
fileConstant | Integer | -> | 4D file constant |
pathType | Integer | -> | fk posix path (default) or fk platform path |
* | -> | * to return file of host database | |
Result | 4D.File | <- | New file object |
Description
The File
command creates and returns a new object of the 4D.File
type. The command accepts two syntaxes:
File ( path { ; pathType } { ; * })
In the path parameter, pass a file path string. You can use a custom string or a filesystem (e.g., "/DATA/myfile.txt").
Only absolute pathnames are supported with the
File
command.
By default, 4D expects a path expressed with the POSIX syntax. If you work with platform pathnames (Windows or macOS), you must declare it using the pathType parameter. The following constants are available:
Constant | Value | Comment |
---|---|---|
fk platform path | 1 | Path expressed with a platform-specific syntax (mandatory in case of platform pathname) |
fk posix path | 0 | Path expressed with POSIX syntax (default) |
File ( fileConstant { ; * } )
In the fileConstant parameter, pass a 4D built-in or system file, using one of the following constants:
Constant | Value | Comment |
---|---|---|
Backup history file | 19 | Backup history file (see Configuration and trace files). Stored in the backup destination folder. |
Backup log file | 13 | Current backup journal file. Stored in the application Logs folder. |
Backup settings file | 1 | Default backup.4DSettings file (xml format), stored in the Settings folder of the project |
Backup settings file for data | 17 | backup.4DSettings file (xml format) for the data file, stored in the Settings folder of the data folder |
Build application log file | 14 | Current log file in xml format of the application builder. Stored in the Logs folder. |
Build application settings file | 20 | Default settings file of the application builder ("buildApp.4DSettings"). Stored in the Settings folder of the project. |
Compacting log file | 6 | Log file of the most recent compacting done with the Compact data file command or the Maintenance and security center. Stored in the Logs folder. |
Current backup settings file | 18 | backup.4DSettings file currently used by the application. It can be the backup settings file (default) or a custom user backup settings file defined for the data file |
Debug log file | 12 | Log file created by the SET DATABASE PARAMETER(Debug log recording) command. Stored in the Logs folder. |
Diagnostic log file | 11 | Log file created by the SET DATABASE PARAMETER(Diagnostic log recording) command. Stored in the Logs folder. |
Directory file | 16 | directory.json file, containing the description of users and groups (if any) for the project application. It can be located either in the user settings folder (default, global to the project), or in the data settings folder (specific to a data file). |
HTTP debug log file | 9 | Log file created by the WEB SET OPTION(Web debug log) command. Stored in the Logs folder. |
HTTP log file | 8 | Log file created by the WEB SET OPTION(Web log recording) command. Stored in Logs folder. |
IMAP Log file | 23 | Log file created by the SET DATABASE PARAMETER(IMAP Log) command. Stored in the Logs folder. |
Last backup file | 2 | Last backup file, named \<applicationName>[bkpNum].4BK , stored at a custom location. |
Last journal integration log file | 22 | Full pathname of the last journal integration log file (stored in the Logs folder of the restored application), if any. This file is created, in auto-repair mode, as soon as a log file integration occurred |
Repair log file | 7 | Log file of database repairs made on the database in the Maintenance and Security Center (MSC). Stored in the Logs folder. |
Request log file | 10 | Standard client/server request log file (excluding Web requests) created by the SET DATABASE PARAMETER(4D Server log recording) or SET DATABASE PARAMETER(Client log recording) commands. If executed on the server, the server log file is returned (stored in the Logs folder on the server). If executed on the client, the client log file is returned (stored in the client local Logs folder). |
SMTP log file | 15 | Log file created by the SET DATABASE PARAMETER(SMTP Log) command. Stored in the Logs folder. |
User settings file | 3 | settings.4DSettings file for all data files, stored in Preferences folder next to structure file if enabled. |
User settings file for data | 4 | settings.4DSettings file for current data file, stored in Preferences folder next to the data file. |
Verification log file | 5 | Log files created by the VERIFY CURRENT DATA FILE and VERIFY DATA FILE commands or the Maintenance and Security Center (MSC). Stored in the Logs folder. |
If the target fileConstant does not exist, a null object is returned. No errors are raised.
If the command is called from a component, pass the optional *
parameter to get the path of the host database. Otherwise, if you omit the *
parameter, a null object is always returned.
4D.File.new()
History
Release | Changes |
---|---|
18 R6 | Added |
4D.File.new ( path : Text { ; pathType : Integer } ) : 4D.File
4D.File.new ( fileConstant : Integer ) : 4D.File
Description
The 4D.File.new()
function creates and returns a new object of the 4D.File
type. It is identical to the File
command (shortcut).
It is recommended to use the
File
shortcut command instead of4D.File.new()
.
.copyTo()
History
Release | Changes |
---|---|
17 R5 | Added |
.copyTo( destinationFolder : 4D.Folder { ; newName : Text } { ; overwrite : Integer } ) : 4D.File
Parameter | Type | Description | |
---|---|---|---|
destinationFolder | 4D.Folder | -> | Destination folder |
newName | Text | -> | Name for the copy |
overwrite | Integer | -> | fk overwrite to replace existing elements |
Result | 4D.File | <- | Copied file |