Aller au contenu principal
Version: 20 R5 BETA

Document Class

Description

.creationDate

Historique
ReleaseModifications
17 R5Ajout

.creationDate : Date

Description

The .creationDate property returns the creation date of the file.

Cette propriété est en lecture seule.

.creationTime

Historique
ReleaseModifications
17 R5Ajout

.creationTime : Time

Description

The .creationTime property returns the creation time of the file (expressed as a number of seconds beginning at 00:00).

Cette propriété est en lecture seule.

.exists

Historique
ReleaseModifications
17 R5Ajout

.exists : Boolean

Description

The .exists property returns true if the file exists on disk, and false otherwise.

Cette propriété est en lecture seule.

.extension

Historique
ReleaseModifications
17 R5Ajout

.extension : Text

Description

The .extension property returns the extension of the file name (if any). Une extension commence toujours par ".". La propriété renvoie une chaîne vide si le nom du fichier n'a pas d'extension.

Cette propriété est en lecture seule.

.fullName

Historique
ReleaseModifications
17 R5Ajout

.fullName : Text

Description

The .fullName property returns the full name of the file, including its extension (if any).

Cette propriété est en lecture seule.

.hidden

Historique
ReleaseModifications
17 R5Ajout

.hidden : Boolean

Description

The .hidden property returns true if the file is set as "hidden" at the system level, and false otherwise.

This property is read/write.

.isAlias

Historique
ReleaseModifications
17 R5Ajout

.isAlias : Boolean

Description

The .isAlias property returns true if the file is an alias, a shortcut, or a symbolic link, and false otherwise.

Cette propriété est en lecture seule.

.isFile

Historique
ReleaseModifications
17 R5Ajout

.isFile : Boolean

Description

The .isFile property returns always true for a file.

Cette propriété est en lecture seule.

.isFolder

Historique
ReleaseModifications
17 R5Ajout

.isFolder : Boolean

Description

The .isFolder property returns always false for a file.

Cette propriété est en lecture seule.

.isWritable

Historique
ReleaseModifications
17 R5Ajout

.isWritable : Boolean

Description

The .isWritable property returns true if the file exists on disk and is writable.

The property checks the ability of the 4D application to write on the disk (access rights), it does not solely rely on the writable attribute of the file.

Cette propriété est en lecture seule.

Example

 $myFile:=File("C:\\Documents\\Archives\\ReadMe.txt";fk platform path)
If($myFile.isWritable)
$myNewFile:=$myFile.setText("Added text")
End if

.modificationDate

Historique
ReleaseModifications
17 R5Ajout

.modificationDate : Date

Description

The .modificationDate property returns the date of the file's last modification.

Cette propriété est en lecture seule.

.modificationTime

Historique
ReleaseModifications
17 R5Ajout

.modificationTime : Time

Description

The .modificationTime property returns the time of the file's last modification (expressed as a number of seconds beginning at 00:00).

Cette propriété est en lecture seule.

.name

Historique
ReleaseModifications
17 R5Ajout

.name : Text

Description

The .name property returns the name of the file without extension (if any).

Cette propriété est en lecture seule.

.original

Historique
ReleaseModifications
17 R5Ajout

.original : 4D.File
.original : 4D.Folder

Description

The .original property returns the target element for an alias, a shortcut, or a symbolic link file. L'élément cible peut être :

  • un objet File
  • un objet Folder

Pour les fichiers sans alias, la propriété retourne le même objet File que le fichier.

Cette propriété est en lecture seule.

.parent

Historique
ReleaseModifications
17 R5Ajout

.parent : 4D.Folder

Description

The .parent property returns the parent folder object of the file. Si le chemin représente un filesystem (ex : "/DATA/"), le filesystem est retourné.

Cette propriété est en lecture seule.

.path

Historique
ReleaseModifications
17 R5Ajout

.path : Text

Description

The .path property returns the POSIX path of the file. Si le chemin représente un filesystem (ex : "/DATA/"), le filesystem est retourné.

Cette propriété est en lecture seule.

.platformPath

Historique
ReleaseModifications
17 R5Ajout

.platformPath : Text

Description

The .platformPath property returns the path of the file expressed with the current platform syntax.

Cette propriété est en lecture seule.

.size

Historique
ReleaseModifications
17 R5Ajout

.size : Real

Description

The .size property returns the size of the file expressed in bytes. Si le fichier n'existe pas sur le disque, la taille est de 0.

Cette propriété est en lecture seule.

.copyTo()

Historique
ReleaseModifications
17 R5Ajout

.copyTo( destinationFolder : 4D.Folder { ; newName : Text } { ; overwrite : Integer } ) : 4D.File

ParamètresTypeDescription
dossierDestination4D.Folder->Dossier de destination
nouveauNomText->Nom de la copie
overwriteInteger->fk overwrite to replace existing elements
Résultat4D.File<-Fichier copié

Description

The .copyTo() function copies the File object into the specified destinationFolder .

The destinationFolder must exist on disk, otherwise an error is generated.

Par défaut, le fichier est copié avec le nom du fichier original. If you want to rename the copy, pass the new name in the newName parameter. Le nouveau nom doit être conforme aux règles de nommage (ex : il ne doit pas contenir de caractères tels que ":", "/", etc.), sinon une erreur est retournée.

If a file with the same name already exists in the destinationFolder, by default 4D generates an error. You can pass the fk overwrite constant in the overwrite parameter to ignore and overwrite the existing file

ConstanteValeurCommentaire
fk overwrite4Écrase les éléments existants, le cas échéant

Valeur retournée

The copied File object.

Exemple

You want to copy a picture file from the user's document folder to the application folder:

var $source; $copy : Object
$source:=Folder(fk documents folder).file("Pictures/photo.png")
$copy:=$source.copyTo(Folder("/PACKAGE");fk overwrite)

.getContent()

Historique
ReleaseModifications
19 R2Retourne 4D.Blob
17 R5Ajout

.getContent( ) : 4D.Blob

ParamètresTypeDescription
Résultat4D.Blob<-Contenu du fichier

Description

The .getContent() function returns a 4D.Blob object containing the entire content of a file. For information on BLOBs, please refer to the BLOB section.

Valeur retournée

A 4D.Blob object.

Exemple

To save a document's contents in a BLOB field:

 var $vPath : Text
$vPath:=Select document("";"*";"Select a document";0)
If(OK=1) //Si un document a été sélectionné
[aTable]aBlobField:=File($vPath;fk platform path).getContent()
End if

.getIcon()

Historique
ReleaseModifications
17 R5Ajout

.getIcon( { size : Integer } ) : Picture

ParamètresTypeDescription
sizeInteger->Longueur du côté de l'image retournée (pixels)
RésultatPicture<-Icône

Description

The .getIcon() function returns the icon of the file.

The optional size parameter specifies the dimensions in pixels of the returned icon. Cette valeur représente la longueur latérale du côté du carré contenant l'icône. La taille des icônes est généralement de 32x32 pixels (“grandes icônes”) ou de 16x16 pixels (“petites icônes”). Si vous passez 0 ou si vous omettez ce paramètre, la version "grandes icônes" est retournée.

Si le fichier n'existe pas sur disque, une icône par défaut vide est retournée.

Valeur retournée

File icon picture.

.getText()

Historique
ReleaseModifications
17 R5Ajout

.getText( { charSetName : Text { ; breakMode : Integer } } ) : Text
.getText( { charSetNum : Integer { ; breakMode : Integer } } ) : Text

ParamètresTypeDescription
charSetNameText->Nom du jeu de caractères
charSetNumInteger->Numéro du jeu de caractères
breakModeInteger->Mode de traitement des retours à la ligne
RésultatText<-Texte du document

Description

The .getText() function returns the contents of the file as text .

Optionnellement, vous pouvez indiquer le jeu de caractères à utiliser pour la lecture du contenu. Vous pouvez passer soit :

  • in charSetName, a string containing the standard set name (for example "ISO-8859-1" or "UTF-8"),
  • or in charSetNum, the MIBEnum ID (number) of the standard set name.

For the list of character sets supported by 4D, refer to the description of the CONVERT FROM TEXT command.

If the document contains a Byte Order Mark (BOM), 4D uses the character set that it has set instead of the one specified in charSetName or charSetNum (this parameter is then ignored). If the document does not contain a BOM and if charSetName or charSetNum is omitted, by default 4D uses the "UTF-8" character set.

In breakMode, you can pass a number indicating the processing to apply to end-of-line characters in the document. Les constantes suivantes du thème "Documents système" sont disponibles :

ConstanteValeurCommentaire
Document unchanged0Aucun traitement
Document with native format1(Défaut) Les fins de ligne sont convertis au format natif de la plate-forme d’exécution : CR (carriage return) sous OS X, CRLF (carriage return + line feed) sous Windows
Document with CRLF2Les fins de ligne sont convertis au format Windows : CRLF (carriage return + line feed)
Document with CR3Les fins de ligne sont convertis au format OS X : CR (carriage return)
Document with LF4Les fins de ligne sont convertis au format Unix : LF (line feed)

By default, when you omit the breakMode parameter, line breaks are processed in native mode (1).

Valeur retournée

Texte du fichier.

Exemple

Considérons le document texte suivant (les champs sont séparés par des tabulations ) :

id name price vat
3 thé 1.06€ 19.6
2 café 1.05€ 19.6

Lorsque vous exécutez ce code :

 $myFile:=Folder(fk documents folder).file("Billing.txt") //UTF-8 par défaut
$txt:=$myFile.getText()

... you get the following for $txt:

"id\tname\tprice\tvat\r\n3\tthé\t1.06€\t19.6\r\n2\tcafé\t1.05€\t19.6"

with \t (tab) as separator and \r\n (CRLF) as line delimiter.

Voici un autre exemple avec le même fichier, mais un délimiteur de ligne différent :

 $txt:=$myFile.getText("UTF-8"; Document with LF)

In this case, the contents of $txt are as follows:

"id\tname\tprice\tvat\n3\tthé\t1.06€\t19.6\n2\tcafé\t1.05€\t19.6"

This time \n (LF) is used as line delimiter.