Saltar al contenido principal
Versión: 20 R5 BETA

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
LanzamientoModificaciones
19 R8Support of fk home folder
17 R5Añadidos

Folder ( path : Text { ; pathType : Integer }{ ; * } ) : 4D.Folder
Folder ( folderConstant : Integer { ; * } ) : 4D.Folder

ParámetrosTipoDescripción
pathText->Ruta de la carpeta
folderConstantInteger->Constante de la carpeta 4D
pathTypeInteger->fk posix path (default) or fk platform path
-->* para devolver la carpeta de la base local
Result4D.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:

ConstanteValorComentario
fk platform path1Ruta expresada con una sintaxis específica de la plataforma (obligatoria en caso de nombre de ruta de plataforma)
fk posix path0Ruta 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:

ConstanteValorComentario
fk applications folder116
fk data folder9Filesystem asociado: "/DATA"
fk database folder4Filesystem asociado: "/PACKAGE"
fk desktop folder115
fk documents folder117Carpeta Documentos del usuario
fk home folder118Current home folder of the user (usually /Users/<username>/)
fk licenses folder1Carpeta que contiene los archivos de licencia 4D de la máquina
fk logs folder7Filesystem asociado: "/LOGS"
fk mobileApps folder10
fk remote database folder3Carpeta de la base de datos 4D creada en cada máquina 4D remota
fk resources folder6Filesystem asociado: "/RESOURCES"
fk system folder100
fk user preferences folder0Carpeta 4D que almacena los archivos de preferencias del usuario en la carpeta personal del usuario
fk web root folder8Carpeta 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
LanzamientoModificaciones
18 R6Añ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 of 4D.Folder.new().

.copyTo()

Historia
LanzamientoModificaciones
17 R5Añadidos

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

ParámetrosTipoDescripción
destinationFolder4D.Folder->Carpeta de destino
newNameText->Nombre para la copia
overwriteInteger->fk overwrite to replace existing elements
Result4D.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

ConstanteValorComentario
fk overwrite4Sobrescribir 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
LanzamientoModificaciones
17 R5Añadidos

.create() : Boolean

ParámetrosTipoDescripción
ResultBoolean<-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
LanzamientoModificaciones
17 R5Añadidos

.createAlias( destinationFolder : 4D.Folder ; aliasName : Text { ; aliasType : Integer } ) : 4D.File

ParámetrosTipoDescripción
destinationFolder4D.Folder->Carpeta de destino para el alias o el acceso directo
aliasNameText->Nombre del alias o del atajo
aliasTypeInteger->Tipo de enlace del alias
Result4D.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:

ConstanteValorComentario
fk alias link0Enlace de alias (por defecto)
fk symbolic link1Enlace 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
LanzamientoModificaciones
17 R5Añadidos

.creationDate : Date

Descripción

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

Esta propiedad es de solo lectura.

.creationTime

Historia
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añadidos

.delete( { option : Integer } )

ParámetrosTipoDescripción
optionInteger->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:

ConstanteValorComentario
Delete only if empty0Elimina la carpeta sólo cuando está vacía
Delete with contents1Elimina 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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añadidos

.file( path : Text ) : 4D.File

ParámetrosTipoDescripción
pathText->Ruta POSIX relativa
Result4D.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
LanzamientoModificaciones
17 R5Añadidos

.files( { options : Integer } ) : Collection

ParámetrosTipoDescripción
optionsInteger->Opciones de la lista de archivos
ResultCollection<-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:

ConstanteValorComentario
fk recursive1La colección contiene los archivos de la carpeta especificada y sus subcarpetas
fk ignore invisible8Los 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
LanzamientoModificaciones
17 R5Añadidos

.folder( path : Text ) : 4D.Folder

ParámetrosTipoDescripción
pathText->Ruta POSIX relativa
Result4D.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
LanzamientoModificaciones
17 R5Añadidos

.folders( { options : Integer } ) : Collection

ParámetrosTipoDescripción
optionsInteger->Opciones de la lista de carpetas
ResultCollection<-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:

ConstanteValorComentario
fk recursive1La colección contiene las carpetas de la carpeta especificada y sus subcarpetas
fk ignore invisible8Los 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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añadidos

.getIcon( { size : Integer } ) : Picture

ParámetrosTipoDescripción
sizeInteger->Longitud del lado de la imagen devuelta (píxeles)
ResultPicture<-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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añadidos

.isAlias : Boolean

Descripción

The .isAlias property returns always false for a Folder object.

Esta propiedad es de solo lectura.

.isFile

Historia
LanzamientoModificaciones
17 R5Añadidos

.isFile : Boolean

Descripción

The .isFile property returns always false for a folder.

Esta propiedad es de solo lectura.

.isFolder

Historia
LanzamientoModificaciones
17 R5Añadidos

.isFolder : Boolean

Descripción

The .isFolder property returns always true for a folder.

Esta propiedad es de solo lectura.

.isPackage

Historia
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añadidos

.moveTo( destinationFolder : 4D.Folder { ; newName : Text } ) : 4D.Folder

ParámetrosTipoDescripción
destinationFolder4D.Folder->Carpeta de destino
newNameText->Nombre completo de la carpeta trasladada
Result4D.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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añ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
LanzamientoModificaciones
17 R5Añadidos

.rename( newName : Text ) : 4D.Folder

ParámetrosTipoDescripción
newNameText->Nuevo nombre completo para la carpeta
Result4D.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")