Saltar para o conteúdo principal
Versão: 20 R5 BETA

Folder

Folder objects are created with the Folder command. Contêm referências a pastas que podem ou não existir efectivamente no 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.

Exemplo

O exemplo seguinte cria uma pasta "JohnSmith":

Form.curfolder:=Folder(fk database folder)
Form.curfolder:=Folder("C:\\Users\\JohnSmith\\";fk platform path)

Pathnames

Folder objects support several pathnames, including filesystems or posix syntax. Supported pathnames are detailed in the Pathnames page.

Objecto 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

História
ReleaseMudanças
19 R8Support of fk home folder
17 R5Adicionado

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

ParâmetroTipoDescrição
pathText->Folder path
folderConstantInteger->Constante Pasta 4D
pathTypeInteger->fk posix path (default) or fk platform path
-->* para devolver a pasta da base de dados do anfitrião
Resultados4D. Folder<-Novo Objeto Folder

Descrição

The Folder command creates and returns a new object of the 4D.Folder type. O comando aceita duas sintaxes:

Folder ( path { ; pathType } { ; * } )

In the path parameter, pass a folder path string. Pode utilizar uma string personalizada ou um sistema de arquivos (por exemplo, "/DATA").

Only absolute pathnames are supported with the Folder command.

Como padrão, 4D espera um caminho expresso com a sintaxe POSIX. If you work with platform pathnames (Windows or macOS), you must declare it using the pathType parameter. Estão disponíveis as seguintes constantes:

ParâmetrosValorComentário
fk platform path1Caminho expresso com uma sintaxe específica da plataforma (obrigatória em caso de caminho de plataforma)
fk posix path0Caminho expresso com a sintaxe POSIX (por padrão)

Folder ( folderConstant { ; * } )

In the folderConstant parameter, pass a 4D built-in or system folder, using one of the following constants:

ParâmetrosValorComentário
fk applications folder116
fk data folder9Sistema de ficheiros associado: "/DATA"
fk database folder4Sistema de arquivos associado: "/PACKAGE"
fk desktop folder115
fk documents folder117Pasta de documentos do utilizador
fk home folder118Current home folder of the user (usually /Users/<username>/)
fk licenses folder1Pasta contendo os arquivos de licença 4D da máquina
fk logs folder7Sistema de arquivos associado: "/LOGS"
fk mobileApps folder10
fk remote database folder3Pasta de base de dados 4D criada em cada máquina 4D remota
fk resources folder6Sistema de arquivos associado: "/DATA"
fk system folder100
fk user preferences folder04D folder that stores user preference files within the \<userName> directory.
fk web root folder8Pasta raiz atual da Web da base de dados: se estiver dentro do pacote "/PACKAGE/percurso", caso contrário, caminho completo

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()

História
ReleaseMudanças
18 R6Adicionado

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

Descrição

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()

História
ReleaseMudanças
17 R5Adicionado

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

ParâmetroTipoDescrição
destinationFolder4D. Folder->Pasta de destino
newNameText->Nome para a copia
overwriteInteger->fk overwrite to replace existing elements
Resultados4D. Folder<-Pasta ou arquivo copiado

Descrição

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

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

Como padrão, a pasta é copiada com o nome da pasta original. If you want to rename the copy, pass the new name in the newName parameter. O novo nome deve cumprir com as regras de nomenclatura (por exemplo, não deve conter caracteres como ":", "/", etc.), do contrário se devolve um erro.

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

ParâmetrosValorComentário
fk overwrite4Sobrescrever os elementos existentes, se houver

Valor retornado

The copied Folder object.

Exemplo

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()

História
ReleaseMudanças
17 R5Adicionado

.create() : Boolean

ParâmetroTipoDescrição
ResultadosParâmetros<-True se a pasta foi criada com sucesso, false caso contrário

Descrição

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. Se a pasta já existir no disco, a função não faz nada (não é atirado nenhum erro) e retorna falso.

Valor retornado

  • True if the folder is created successfully;
  • False if a folder with the same name already exists or if an error occured.

Exemplo 1

Criar uma pasta vazia na pasta da base de dados:

var $created : Boolean
$created:=Folder("/PACKAGE/SpecialPrefs").create()

Exemplo 2

Criação da pasta "/Arquivos2019/Janeiro/" na pasta da base de dados:

$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()

História
ReleaseMudanças
17 R5Adicionado

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

ParâmetroTipoDescrição
destinationFolder4D. Folder->Pasta de destino para o pseudónimo ou atalho
aliasNameText->Nome do pseudónimo ou atalho
aliasTypeInteger->Tipo de ligação do pseudónimo
Resultados4D. File<-Alias ou referência de atalho

Descrição

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 padrão em macOS, a função cria um pseudónimo padrão. You can also create a symbolic link by using the aliasType parameter. Estão disponíveis as seguintes constantes:

ParâmetrosValorComentário
fk alias link0Alias link (padrão)
fk symbolic link1Link simbólico (só em macOS)

On Windows, a shortcut (.lnk file) is always created (the aliasType parameter is ignored).

Returned object

A 4D.File object with the isAlias property set to true.

Exemplo

Deseja criar um pseudónimo para uma pasta de arquivo na sua pasta de base de dados:

$myFolder:=Folder("C:\\Documents\\Archives\\2019\\January";fk platform path)
$aliasFile:=$myFolder.createAlias(Folder("/PACKAGE");"Jan2019")

.creationDate

História
ReleaseMudanças
17 R5Adicionado

.creationDate : Date

Descrição

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

This property is read-only.

.creationTime

História
ReleaseMudanças
17 R5Adicionado

.creationTime : Time

Descrição

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

This property is read-only.

.delete()

História
ReleaseMudanças
17 R5Adicionado

.delete( { option : Integer } )

ParâmetroTipoDescrição
optionInteger->Opção de eliminação de pasta

Descrição

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. Se quiser que o comando possa apagar pastas que não estejam vazias, deve utilizar o parâmetro de opção com uma das seguintes constantes:

ParâmetrosValorComentário
Delete only if empty0Elimina a pasta apenas quando está vazia
Delete with contents1Apaga a pasta juntamente com tudo o que a mesma contém

When Delete only if empty is passed or if you omit the option parameter:

  • A pasta só é apagada se estiver vazia; caso contrário, o comando não faz nada e é gerado um erro -47.
  • Se a pasta não existir, o erro -120 é gerado.

When Delete with contents is passed:

  • A pasta, juntamente com todo o seu conteúdo, é apagada. 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.
  • Se esta pasta, ou qualquer dos arquivos que conter, não puder ser apagada, a eliminação é abortada assim que o primeiro elemento inacessível for detectado, e um erro(*) é devolvido. Neste caso, a pasta pode ser apenas parcialmente apagada. When deletion is aborted, you can use the GET LAST ERROR STACK command to retrieve the name and path of the offending file.
  • Se a pasta não existir, o comando não faz nada e nenhum erro é devolvido. (*) Windows: -54 (Attempt to open locked file for writing) macOS: -45 (The file is locked or the pathname is not correct)

.exists

História
ReleaseMudanças
17 R5Adicionado

.exists : Boolean

Descrição

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

This property is read-only.

.extension

História
ReleaseMudanças
17 R5Adicionado

.extension : Text

Descrição

The .extension property returns the extension of the folder name (if any). Uma extensão sempre começa com ".". Uma extensão sempre começa com "." A propriedade devolve uma string vazia se o nome da pasta não tiver extensão.

This property is read-only.

.file()

História
ReleaseMudanças
17 R5Adicionado

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

ParâmetroTipoDescrição
pathText->Rota POSIX relativa
Resultados4D. File<-File object (null if invalid path)

Descrição

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. A rota se avaliará a partir da pasta pai como raíz.

Valor retornado

A File object or null if path is invalid.

Exemplo

var $myPDF : 4D. File
$myPDF:=Folder(fk documents folder).file("Pictures/info.pdf")

.files()

História
ReleaseMudanças
17 R5Adicionado

.files( { options : Integer } ) : Collection

ParâmetroTipoDescrição
optionsInteger->Opções da lista de arquivos
ResultadosCollection<-Coleção de objetos de arquivo filho

Descrição

The .files() function returns a collection of File objects contained in the folder.

Os apelidos ou links simbolicos não são resolvidos.

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:

ParâmetrosValorComentário
fk recursive1A coleção contém arquivos da pasta especificada e suas subpastas
fk ignore invisible8Arquivos invisíveis não estão listados

Valor retornado

Collection of File objects.

Exemplo 1

Se quiser saber se há arquivos invisíveis na pasta Database:

 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

Exemplo 2

Se quiser obter todos os arquivos que não são invisíveis na pasta Documents:

 var $recursive : Collection
$recursive:=Folder(fk documents folder).files(fk recursive+fk ignore invisible)

.folder()

História
ReleaseMudanças
17 R5Adicionado

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

ParâmetroTipoDescrição
pathText->Rota POSIX relativa
Resultados4D. Folder<-Created folder object (null if invalid path)

Descrição

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. A rota se avaliará a partir da pasta pai como raíz.

Valor retornado

A Folder object or null if path is invalid.

Exemplo

 var $mypicts : 4D. Folder
$mypicts:=Folder(fk documents folder).folder("Pictures")

.folders()

História
ReleaseMudanças
17 R5Adicionado

.folders( { options : Integer } ) : Collection

ParâmetroTipoDescrição
optionsInteger->Opções da lista de pasta
ResultadosCollection<-Coleção de objetos de pasta filho

Descrição

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:

ParâmetrosValorComentário
fk recursive1A coleção contém pastas da pasta especificada e suas subpastas
fk ignore invisible8Pastas invisíveis não estão listados

Valor retornado

Collection of Folder objects.

Exemplo

Se quiser a coleção de todas as pastas e subpastas da pasta database:

 var $allFolders : Collection
$allFolders:=Folder("/PACKAGE").folders(fk recursive)

.fullName

História
ReleaseMudanças
17 R5Adicionado

.fullName : Text

Descrição

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

This property is read-only.

.getIcon()

História
ReleaseMudanças
17 R5Adicionado

.getIcon( { size : Integer } ) : Picture

ParâmetroTipoDescrição
sizeInteger->Longitude de lado da imagem devolvida (píxeles)
ResultadosImagem<-Ícone

Descrição

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 em realidade a longitude do lado do quadrado que contém o icone. Icones são geralmente definidos como 32x32 píxels ('icones grandes') ou 16x16 ('icones pequenos'). Se passar 0 ou omitir este parâmetro, se devolve a versão 'icone grande'

Se a pasta não existir no disco, se devolve um icone vazio como padrão.

Valor retornado

Folder icon picture.

.hidden

História
ReleaseMudanças
17 R5Adicionado

.hidden : Boolean

Descrição

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

This property is read-only.

.isAlias

História
ReleaseMudanças
17 R5Adicionado

.isAlias : Boolean

Descrição

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

This property is read-only.

.isFile

História
ReleaseMudanças
17 R5Adicionado

.isFile : Boolean

Descrição

The .isFile property returns always false for a folder.

This property is read-only.

.isFolder

História
ReleaseMudanças
17 R5Adicionado

.isFolder : Boolean

Descrição

The .isFolder property returns always true for a folder.

This property is read-only.

.isPackage

História
ReleaseMudanças
17 R5Adicionado

.isPackage : Boolean

Descrição

The .isPackage property returns true if the folder is a package on macOS (and exists on disk). .

On Windows, .isPackage always returns false.

This property is read-only.

.modificationDate

História
ReleaseMudanças
17 R5Adicionado

.modificationDate : Date

Descrição

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

This property is read-only.

.modificationTime

História
ReleaseMudanças
17 R5Adicionado

.modificationTime : Time

Descrição

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

This property is read-only.

.moveTo()

História
ReleaseMudanças
17 R5Adicionado

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

ParâmetroTipoDescrição
destinationFolder4D. Folder->Pasta de destino
newNameText->Nome completo para a pasta movida
Resultados4D. Folder<-Pasta movida

Descrição

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 padrão, a pasta mantém o seu nome quando movida. If you want to rename the moved folder, pass the new full name in the newName parameter. O novo nome deve cumprir com as regras de nomenclatura (por exemplo, não deve conter caracteres como ":", "/", etc.), do contrário se devolve um erro.

Returned object

The moved Folder object.

Exemplo

Quer mover-se e renomear uma pasta:

 var $tomove; $moved : Object
$docs:=Folder(fk documents folder)
$tomove:=$docs.folder("Pictures")
$tomove2:=$tomove.moveTo($docs.folder("Archives");"Pic_Archives")

.name

História
ReleaseMudanças
17 R5Adicionado

.name : Text

Descrição

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

This property is read-only.

.original

História
ReleaseMudanças
17 R5Adicionado

.original : 4D.Folder

Descrição

The .original property returns the same Folder object as the folder.

This property is read-only.

Esta propriedade está disponible nas pastas para permitir que o código genérico processe pastas ou arquivos.

.parent

História
ReleaseMudanças
17 R5Adicionado

.parent : 4D.Folder

Descrição

The .parent property returns the parent folder object of the folder. .

Se a pasta não tiver um pai (raiz), é devolvido o valor nulo.

This property is read-only.

.path

História
ReleaseMudanças
17 R5Adicionado

.path : Text

Descrição

The .path property returns the POSIX path of the folder. .

This property is read-only.

.platformPath

História
ReleaseMudanças
17 R5Adicionado

.platformPath : Text

Descrição

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

This property is read-only.

.rename()

História
ReleaseMudanças
17 R5Adicionado

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

ParâmetroTipoDescrição
newNameText->Novo nome completo para a pasta
Resultados4D. Folder<-Renomeado arquivo

Descrição

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. Se já existir um ficheiro com o mesmo nome, é devolvido um erro.

Returned object

The renamed Folder object.

Exemplo

 var $toRename : 4D. Folder
$toRename:=Folder("/RESOURCES/Pictures").rename("Images")