Skip to main content
Version: 20 R10

Folder

Folder objects are created with the Folder command. They contain references to folders that may or may not actually exist on disk. 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.

Example

The following example creates a "JohnSmith" folder:

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.

Folder object





























4D.Folder.new()

History
ReleaseChanges
18 R6Added

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

Description

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

.create()

History
ReleaseChanges
17 R5Added

.create()* : Boolean

ParameterTypeDescription
ResultBoolean<-True if the folder was created successfully, false otherwise

Description

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. If the folder already exists on disk, the function does nothing (no error is thrown) and returns false.

Returned value

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

Example 1

Create an empty folder in the database folder:

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

Example 2

Creation of the "/Archives2019/January/" folder in the database folder:

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

History
ReleaseChanges
17 R5Added

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

ParameterTypeDescription
destinationFolder4D.Folder->Destination folder for the alias or shortcut
aliasNameText->Name of the alias or shortcut
aliasTypeInteger->Type of the alias link
Result4D.File<-Alias or shortcut reference

Description

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.

By default on macOS, the function creates a standard alias. You can also create a symbolic link by using the aliasType parameter. The following constants are available:

ConstantValueComment
fk alias link0Alias link (default)
fk symbolic link1Symbolic link (macOS only)

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.

Example

You want to create an alias to an archive folder in your database folder:

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

.delete()

History
ReleaseChanges
17 R5Added

.delete*( { option : Integer } )

ParameterTypeDescription
optionInteger->Folder deletion option

Description

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. If you want the command to be able to delete folders that are not empty, you must use the option parameter with one of the following constants:

ConstantValueComment
Delete only if empty0Deletes folder only when it is empty
Delete with contents1Deletes folder along with everything it contains

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

  • The folder is only deleted if it is empty; otherwise, the command does nothing and an error -47 is generated.
  • If the folder does not exist, the error -120 is generated.

When Delete with contents is passed:

  • The folder, along with all of its contents, is deleted. 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.
  • If this folder, or any of the files it contains, cannot be deleted, deletion is aborted as soon as the first inaccessible element is detected, and an error(*) is returned. In this case, the folder may be only partially deleted. When deletion is aborted, you can use the Last errors command to retrieve the name and path of the offending file.
  • If the folder does not exist, the command does nothing and no error is returned. (*) Windows: -54 (Attempt to open locked file for writing) macOS: -45 (The file is locked or the pathname is not correct)

.moveTo()

History
ReleaseChanges
17 R5Added

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

ParameterTypeDescription
destinationFolder4D.Folder->Destination folder
newNameText->Full name for the moved folder
Result4D.Folder<-Moved folder

Description

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.

By default, the folder retains its name when moved. If you want to rename the moved folder, pass the new full name in the newName parameter. The new name must comply with naming rules (e.g., it must not contain characters such as ":", "/", etc.), otherwise an error is returned.

Returned object

The moved Folder object.

Example

You want to move and rename a folder:

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

.rename()

History
ReleaseChanges
17 R5Added

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

ParameterTypeDescription
newNameText->New full name for the folder
Result4D.Folder<-Renamed folder

Description

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. If a file with the same name already exists, an error is returned.

Returned object

The renamed Folder object.

Example

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