Folder
Folder
objects are created with the Folder
command. Contienen referencias a carpetas que pueden o no existir realmente en el disco. For example, when you execute the Folder
command to create a new folder, a valid Folder
object is created but nothing is actually stored on disk until you call the folder.create()
function.
Ejemplo
El siguiente ejemplo crea una carpeta "JohnSmith":
Form.curfolder:=Folder(fk database folder)
Form.curfolder:=Folder("C:\\Users\\JohnSmith\\";fk platform path)
Rutas de acceso
Folder
objects support several pathnames, including filesystems
or posix
syntax. Supported pathnames are detailed in the Pathnames page.
Objeto Folder
.copyTo( destinationFolder : 4D.Folder { ; newName : Text } { ; overwrite : Integer } ) : 4D.Folder copies the Folder object into the specified destinationFolder |
.create() : Boolean creates a folder on disk according to the properties of the Folder 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 folder |
.creationTime : Time the creation time of the folder |
.delete( { option : Integer } ) deletes the folder |
.exists : Boolean true if the folder exists on disk |
.extension : Text returns the extension of the folder name (if any) |
.file( path : Text ) : 4D.File a File object inside the Folder object and returns its reference |
.files( { options : Integer } ) : Collection a collection of File objects contained in the folder |
.folder( path : Text ) : 4D.Folder creates a Folder object inside the parent Folder object and returns its reference |
.folders( { options : Integer } ) : Collection returns a collection of Folder objects contained in the parent folder |
.fullName : Text returns the full name of the folder, including its extension (if any) |
.getIcon( { size : Integer } ) : Picture returns the icon of the folder |
.hidden : Boolean true if the folder is set as "hidden" at the system level |
.isAlias : Boolean always false for a Folder object |
.isFile : Boolean always false for a folder |
.isFolder : Boolean always true for a folder |
.isPackage : Boolean true if the folder is a package on macOS (and exists on disk) |
.modificationDate : Date the date of the folder's last modification |
.modificationTime : Time the time of the folder's last modification |
.name : Text the name of the folder, without extension (if any) |
.original : 4D.Folder the same Folder object as the folder |
.parent : 4D.Folder the parent folder object of the folder |
.path : Text the POSIX path of the folder |
.platformPath : Text the path of the folder expressed with the current platform syntax |
.moveTo( destinationFolder : 4D.Folder { ; newName : Text } ) : 4D.Folder moves or renames the Folder object (source folder) into the specified destinationFolder |
.rename( newName : Text ) : 4D.Folder renames the folder with the name you passed in newName and returns the renamed Folder object |
Folder
Historia
Lanzamiento | Modificaciones |
---|---|
19 R8 | Support of fk home folder |
17 R5 | Añadidos |
Folder ( path : Text { ; pathType : Integer }{ ; * } ) : 4D.Folder
Folder ( folderConstant : Integer { ; * } ) : 4D.Folder
Parámetros | Tipo | Descripción | |
---|---|---|---|
path | Text | -> | Ruta de la carpeta |
folderConstant | Integer | -> | Constante de la carpeta 4D |
pathType | Integer | -> | fk posix path (default) or fk platform path |
- | -> | * para devolver la carpeta de la base local | |
Result | 4D.Folder | <- | Nuevo objeto de carpeta |
Descripción
The Folder
command creates and returns a new object of the 4D.Folder
type. El comando acepta dos sintaxis:
Folder ( path { ; pathType } { ; * } )
In the path parameter, pass a folder path string. Puede utilizar una cadena personalizada o un filesystem (por ejemplo, "/DATA").
Only absolute pathnames are supported with the
Folder
command.
Por defecto, 4D espera una ruta expresada con la sintaxis POSIX. If you work with platform pathnames (Windows or macOS), you must declare it using the pathType parameter. Las siguientes constantes están disponibles:
Constante | Valor | Comentario |
---|---|---|
fk platform path | 1 | Ruta expresada con una sintaxis específica de la plataforma (obligatoria en caso de nombre de ruta de plataforma) |
fk posix path | 0 | Ruta expresada con sintaxis POSIX (por defecto) |
Folder ( folderConstant { ; * } )
In the folderConstant parameter, pass a 4D built-in or system folder, using one of the following constants:
Constante | Valor | Comentario |
---|---|---|
fk applications folder | 116 | |
fk data folder | 9 | Filesystem asociado: "/DATA" |
fk database folder | 4 | Filesystem asociado: "/PACKAGE" |
fk desktop folder | 115 | |
fk documents folder | 117 | Carpeta Documentos del usuario |
fk home folder | 118 | Current home folder of the user (usually /Users/<username>/ ) |
fk licenses folder | 1 | Carpeta que contiene los archivos de licencia 4D de la máquina |
fk logs folder | 7 | Filesystem asociado: "/LOGS" |
fk mobileApps folder | 10 | |
fk remote database folder | 3 | Carpeta de la base de datos 4D creada en cada máquina 4D remota |
fk resources folder | 6 | Filesystem asociado: "/RESOURCES" |
fk system folder | 100 | |
fk user preferences folder | 0 | Carpeta 4D que almacena los archivos de preferencias del usuario en la carpeta personal del usuario |
fk web root folder | 8 | Carpeta raíz web actual de la base de datos: si está dentro del paquete "/PACKAGE/path", si no ruta completa |
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.
On Windows, in merged clients, the location of built-in folders is modified if the
ShareLocalResourcesOnWindowsClient
BuildApp key is used.
4D.Folder.new()
Historia
Lanzamiento | Modificaciones |
---|---|
18 R6 | Añadidos |
4D.Folder.new ( path : Text { ; pathType : Integer }{ ; * } ) : 4D.Folder
4D.Folder.new ( folderConstant : Integer { ; * } ) : 4D.Folder
Descripción
The 4D.Folder.new()
function creates and returns a new object of the 4D.Folder
type. It is identical to the Folder
command (shortcut).
It is recommended to use the
Folder
shortcut command instead of4D.Folder.new()
.
.copyTo()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.copyTo( destinationFolder : 4D.Folder { ; newName : Text } { ; overwrite : Integer } ) : 4D.Folder
Parámetros | Tipo | Descripción | |
---|---|---|---|
destinationFolder | 4D.Folder | -> | Carpeta de destino |
newName | Text | -> | Nombre para la copia |
overwrite | Integer | -> | fk overwrite to replace existing elements |
Result | 4D.Folder | <- | Carpeta o archivo copiado |
Descripción
The .copyTo()
function copies the Folder
object into the specified destinationFolder.
The destinationFolder must exist on disk, otherwise an error is generated.
Por defecto, la carpeta se copia con el nombre de la carpeta original. If you want to rename the copy, pass the new name in the newName parameter. El nuevo nombre debe cumplir con las reglas de nomenclatura (por ejemplo, no debe contener caracteres como ":", "/", etc.), de lo contrario se devuelve un error.
If a folder 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
Constante | Valor | Comentario |
---|---|---|
fk overwrite | 4 | Sobrescribir los elementos existentes, si los hay |
Valor devuelto
The copied Folder
object.
Ejemplo
You want to copy a Pictures folder from the user's Document folder to the Database folder:
var $userImages; $copiedImages : 4D.Folder
$userImages:=Folder(fk documents folder).folder("Pictures")
$copiedImages:=$userImages.copyTo(Folder(fk database folder);fk overwrite)
.create()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.create() : Boolean
Parámetros | Tipo | Descripción | |
---|---|---|---|
Result | Boolean | <- | True si la carpeta se ha creado con éxito, false en caso contrario |
Descripción
The .create()
function creates a folder on disk according to the properties of the Folder
object.
If necessary, the function creates the folder hierachy as described in the platformPath or path properties. Si la carpeta ya existe en el disco, la función no hace nada (no se lanza ningún error) y devuelve false.
Valor devuelto
- True if the folder is created successfully;
- False if a folder with the same name already exists or if an error occured.
Ejemplo 1
Cree una carpeta vacía en la carpeta de la base:
var $created : Boolean
$created:=Folder("/PACKAGE/SpecialPrefs").create()
Ejemplo 2
Creación de la carpeta "/Archives2019/January/" en la carpeta de la base:
$newFolder:=Folder("/PACKAGE/Archives2019/January")
If($newFolder.create())
ALERT("The "+$newFolder.name+" folder was created.")
Else
ALERT("Impossible to create a "+$newFolder.name+" folder.")
End if
.createAlias()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.createAlias( destinationFolder : 4D.Folder ; aliasName : Text { ; aliasType : Integer } ) : 4D.File
Parámetros | Tipo | Descripción | |
---|---|---|---|
destinationFolder | 4D.Folder | -> | Carpeta de destino para el alias o el acceso directo |
aliasName | Text | -> | Nombre del alias o del atajo |
aliasType | Integer | -> | Tipo de enlace del alias |
Result | 4D.File | <- | Referencia de alias o de acceso directo |
Descripción
The .createAlias()
function creates an alias (macOS) or a shortcut (Windows) to the folder with the specified aliasName name in the folder designated by the destinationFolder object.
Pass the name of the alias or shortcut to create in the aliasName parameter.
Por defecto en macOS, la función crea un alias estándar. You can also create a symbolic link by using the aliasType parameter. Las siguientes constantes están disponibles:
Constante | Valor | Comentario |
---|---|---|
fk alias link | 0 | Enlace de alias (por defecto) |
fk symbolic link | 1 | Enlace simbólico (sólo para macOS) |
On Windows, a shortcut (.lnk file) is always created (the aliasType parameter is ignored).
Objeto devuelto
A 4D.File
object with the isAlias
property set to true.
Ejemplo
Quiere crear un alias para una carpeta de archivos en su carpeta principal:
$myFolder:=Folder("C:\\Documents\\Archives\\2019\\January";fk platform path)
$aliasFile:=$myFolder.createAlias(Folder("/PACKAGE");"Jan2019")
.creationDate
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.creationDate : Date
Descripción
The .creationDate
property returns the creation date of the folder.
Esta propiedad es de solo lectura.
.creationTime
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.creationTime : Time
Descripción
The .creationTime
property returns the creation time of the folder (expressed as a number of seconds beginning at 00:00).
Esta propiedad es de solo lectura.
.delete()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.delete( { option : Integer } )
Parámetros | Tipo | Descripción | |
---|---|---|---|
option | Integer | -> | Opción de eliminación de carpeta |
Descripción
The .delete()
function deletes the folder.
By default, for security reasons, if you omit the option parameter, .delete( )
only allows empty folders to be deleted. Si desea que el comando pueda eliminar carpetas que no están vacías, debe utilizar el parámetro option con una de las siguientes constantes:
Constante | Valor | Comentario |
---|---|---|
Delete only if empty | 0 | Elimina la carpeta sólo cuando está vacía |
Delete with contents | 1 | Elimina la carpeta junto con todo lo que contiene |
When Delete only if empty
is passed or if you omit the option parameter:
- La carpeta sólo se elimina si está vacía; en caso contrario, el comando no hace nada y se genera un error -47.
- Si la carpeta no existe, se genera el error -120.
When Delete with contents
is passed:
- La carpeta, junto con todo su contenido, se elimina. Warning: Even when this folder and/or its contents are locked or set to read-only, if the current user has suitable access rights, the folder (and contents) is still deleted.
- Si esta carpeta, o cualquiera de los archivos que contiene, no puede ser eliminada, la eliminación se interrumpe tan pronto como se detecta el primer elemento inaccesible y se devuelve un error(*). En este caso, la carpeta puede ser eliminada sólo parcialmente. When deletion is aborted, you can use the
GET LAST ERROR STACK
command to retrieve the name and path of the offending file. - Si la carpeta no existe, el comando no hace nada y no devuelve ningún error. (*) Windows: -54 (Attempt to open locked file for writing) macOS: -45 (The file is locked or the pathname is not correct)
.exists
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.exists : Boolean
Descripción
The .exists
property returns true if the folder exists on disk, and false otherwise.
Esta propiedad es de solo lectura.
.extension
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.extension : Text
Descripción
The .extension
property returns the extension of the folder name (if any). Una extensión siempre comienza por ".". La propiedad devuelve una cadena vacía si el nombre de la carpeta no tiene extensión.
Esta propiedad es de solo lectura.
.file()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.file( path : Text ) : 4D.File
Parámetros | Tipo | Descripción | |
---|---|---|---|
path | Text | -> | Ruta POSIX relativa |
Result | 4D.File | <- | File object (null if invalid path) |
Descripción
The .file()
function creates a File
object inside the Folder
object and returns its reference.
In path, pass a relative POSIX path to designate the file to return. La ruta se evaluará a partir de la carpeta padre como raíz.
Valor devuelto
A File
object or null if path is invalid.
Ejemplo
var $myPDF : 4D.File
$myPDF:=Folder(fk documents folder).file("Pictures/info.pdf")
.files()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.files( { options : Integer } ) : Collection
Parámetros | Tipo | Descripción | |
---|---|---|---|
options | Integer | -> | Opciones de la lista de archivos |
Result | Collection | <- | Colección de objetos de archivo hijo |
Descripción
The .files()
function returns a collection of File
objects contained in the folder.
Los alias o enlaces simbólicos no se resuelven.
By default, if you omit the options parameter, only the files at the first level of the folder are returned in the collection, as well as invisible files or folders. You can modify this by passing, in the options parameter, one or more of the following constants:
Constante | Valor | Comentario |
---|---|---|
fk recursive | 1 | La colección contiene los archivos de la carpeta especificada y sus subcarpetas |
fk ignore invisible | 8 | Los archivos invisibles no aparecen en la lista |
Valor devuelto
Collection of File
objects.
Ejemplo 1
Quiere saber si hay archivos invisibles en la carpeta de la base:
var $all; $noInvisible : Collection
$all:=Folder(fk database folder).files()
$noInvisible:=Folder(fk database folder).files(fk ignore invisible)
If($all.length#$noInvisible.length)
ALERT("Database folder contains hidden files.")
End if
Ejemplo 2
Quiere obtener todos los archivos que no son invisibles en la carpeta Documents:
var $recursive : Collection
$recursive:=Folder(fk documents folder).files(fk recursive+fk ignore invisible)
.folder()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.folder( path : Text ) : 4D.Folder
Parámetros | Tipo | Descripción | |
---|---|---|---|
path | Text | -> | Ruta POSIX relativa |
Result | 4D.Folder | <- | Created folder object (null if invalid path) |
Descripción
The .folder()
function creates a Folder
object inside the parent Folder
object and returns its reference.
In path, pass a relative POSIX path to designate the folder to return. La ruta se evaluará a partir de la carpeta padre como raíz.
Valor devuelto
A Folder
object or null if path is invalid.
Ejemplo
var $mypicts : 4D.Folder
$mypicts:=Folder(fk documents folder).folder("Pictures")
.folders()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.folders( { options : Integer } ) : Collection
Parámetros | Tipo | Descripción | |
---|---|---|---|
options | Integer | -> | Opciones de la lista de carpetas |
Result | Collection | <- | Colección de objetos de carpeta hijo |
Descripción
The .folders()
function returns a collection of Folder
objects contained in the parent folder.
By default, if you omit the options parameter, only the folders at the first level of the folder are returned in the collection. You can modify this by passing, in the options parameter, one or more of the following constants:
Constante | Valor | Comentario |
---|---|---|
fk recursive | 1 | La colección contiene las carpetas de la carpeta especificada y sus subcarpetas |
fk ignore invisible | 8 | Los archivos invisibles no aparecen en la lista |
Valor devuelto
Collection of Folder
objects.
Ejemplo
Quiere obtener la colección de todas las carpetas y subcarpetas de la carpeta de la base:
var $allFolders : Collection
$allFolders:=Folder("/PACKAGE").folders(fk recursive)
.fullName
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.fullName : Text
Descripción
The .fullName
property returns the full name of the folder, including its extension (if any).
Esta propiedad es de solo lectura.
.getIcon()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.getIcon( { size : Integer } ) : Picture
Parámetros | Tipo | Descripción | |
---|---|---|---|
size | Integer | -> | Longitud del lado de la imagen devuelta (píxeles) |
Result | Picture | <- | Icono |
Descripción
The .getIcon()
function returns the icon of the folder.
The optional size parameter specifies the dimensions in pixels of the returned icon. Este valor representa en realidad la longitud del lado del cuadrado que contiene el icono. Los iconos suelen definirse en 32x32 píxeles ("iconos grandes") o 16x16 píxeles ("iconos pequeños"). Si pasa 0 u omite este parámetro, se devuelve la versión "icono grande".
Si la carpeta no existe en el disco, se devuelve un icono vacío por defecto.
Valor devuelto
Folder icon picture.
.hidden
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.hidden : Boolean
Descripción
The .hidden
property returns true if the folder is set as "hidden" at the system level, and false otherwise.
Esta propiedad es de solo lectura.
.isAlias
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.isAlias : Boolean
Descripción
The .isAlias
property returns always false for a Folder
object.
Esta propiedad es de solo lectura.
.isFile
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.isFile : Boolean
Descripción
The .isFile
property returns always false for a folder.
Esta propiedad es de solo lectura.
.isFolder
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.isFolder : Boolean
Descripción
The .isFolder
property returns always true for a folder.
Esta propiedad es de solo lectura.
.isPackage
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.isPackage : Boolean
Descripción
The .isPackage
property returns true if the folder is a package on macOS (and exists on disk). En caso contrario, devuelve false.
On Windows, .isPackage
always returns false.
Esta propiedad es de solo lectura.
.modificationDate
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.modificationDate : Date
Descripción
The .modificationDate
property returns the date of the folder's last modification.
Esta propiedad es de solo lectura.
.modificationTime
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.modificationTime : Time
Descripción
The .modificationTime
property returns the time of the folder's last modification (expressed as a number of seconds beginning at 00:00).
Esta propiedad es de solo lectura.
.moveTo()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.moveTo( destinationFolder : 4D.Folder { ; newName : Text } ) : 4D.Folder
Parámetros | Tipo | Descripción | |
---|---|---|---|
destinationFolder | 4D.Folder | -> | Carpeta de destino |
newName | Text | -> | Nombre completo de la carpeta trasladada |
Result | 4D.Folder | <- | Carpeta movida |
Descripción
The .moveTo( )
function moves or renames the Folder
object (source folder) into the specified destinationFolder.
The destinationFolder must exist on disk, otherwise an error is generated.
Por defecto, la carpeta conserva su nombre cuando se mueve. If you want to rename the moved folder, pass the new full name in the newName parameter. El nuevo nombre debe cumplir con las reglas de nomenclatura (por ejemplo, no debe contener caracteres como ":", "/", etc.), de lo contrario se devuelve un error.
Objeto devuelto
The moved Folder
object.
Ejemplo
Quiere mover y renombrar una carpeta:
var $tomove; $moved : Object
$docs:=Folder(fk documents folder)
$tomove:=$docs.folder("Pictures")
$tomove2:=$tomove.moveTo($docs.folder("Archives");"Pic_Archives")
.name
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.name : Text
Descripción
The .name
property returns the name of the folder, without extension (if any).
Esta propiedad es de solo lectura.
.original
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.original : 4D.Folder
Descripción
The .original
property returns the same Folder object as the folder.
Esta propiedad es de solo lectura.
Esta propiedad está disponible en las carpetas para permitir que el código genérico procese carpetas o archivos.
.parent
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.parent : 4D.Folder
Descripción
The .parent
property returns the parent folder object of the folder. Si la ruta representa una ruta del sitema (por ejemplo, "/DATA/"), se devuelve la ruta del sistema.
Si la carpeta no tiene un padre (raíz), se devuelve el valor null.
Esta propiedad es de solo lectura.
.path
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.path : Text
Descripción
The .path
property returns the POSIX path of the folder. Si la ruta representa un filesystem (por ejemplo, "/DATA/"), se devuelve el filesystem.
Esta propiedad es de solo lectura.
.platformPath
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.platformPath : Text
Descripción
The .platformPath
property returns the path of the folder expressed with the current platform syntax.
Esta propiedad es de solo lectura.
.rename()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.rename( newName : Text ) : 4D.Folder
Parámetros | Tipo | Descripción | |
---|---|---|---|
newName | Text | -> | Nuevo nombre completo para la carpeta |
Result | 4D.Folder | <- | Carpeta renombrada |
Descripción
The .rename()
function renames the folder with the name you passed in newName and returns the renamed Folder
object.
The newName parameter must comply with naming rules (e.g., it must not contain characters such as ":", "/", etc.), otherwise an error is returned. Si ya existe un archivo con el mismo nombre, se devuelve un error.
Objeto devuelto
The renamed Folder
object.
Ejemplo
var $toRename : 4D.Folder
$toRename:=Folder("/RESOURCES/Pictures").rename("Images")