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.
例題
The following example creates a "JohnSmith" folder:
Form.curfolder:=Folder(fk database folder)
Form.curfolder:=Folder("C:\\Users\\JohnSmith\\";fk platform path)
Folder object
Folder
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
Folder ( path : Text { ; pathType : Integer }{ ; * } ) : 4D.Folder
Folder ( folderConstant : Integer { ; * } ) : 4D.Folder
参照 | タイプ | 説明 | |
---|---|---|---|
path | テキスト | -> | フォルダーパス |
folderConstant | 整数 | -> | 4Dフォルダー定数 |
pathType | 整数 | -> | fk posix path (デフォルト) または fk platform path |
* | -> | ホストデータベースのフォルダーを返すには * を渡します | |
戻り値 | 4D.Folder | <- | 新規フォルダーオブジェクト |
説明
Folder
コマンドは、 4D.Folder
型の新しいオブジェクトを作成して返します。 The command accepts two syntaxes:
Folder ( path { ; pathType } { ; * } )
In the path parameter, pass a folder path string. You can use a custom string or a filesystem (e.g., "/DATA").
Only absolute pathnames are supported with the
Folder
command.
By default, 4D expects a path expressed with the POSIX syntax. If you work with platform pathnames (Windows or macOS), you must declare it using the pathType parameter. The following constants are available:
定数 | 結果 | 説明 |
---|---|---|
fk platform path | 1 | Path expressed with a platform-specific syntax (mandatory in case of platform pathname) |
fk posix path | 0 | Path expressed with POSIX syntax (default) |
Folder ( folderConstant { ; * } )
In the folderConstant parameter, pass a 4D built-in or system folder, using one of the following constants:
定数 | 結果 | 説明 |
---|---|---|
fk applications folder | 116 | |
fk data folder | 9 | Associated filesystem: "/DATA" |
fk database folder | 4 | Associated filesystem: "/PACKAGE" |
fk desktop folder | 115 | |
fk documents folder | 117 | Document folder of the user |
fk licenses folder | 1 | Folder containing the machine's 4D license files |
fk logs folder | 7 | Associated filesystem: "/LOGS" |
fk mobileApps folder | 10 | Associated filesystem: "/DATA" |
fk remote database folder | 3 | 4D database folder created on each 4D remote machine |
fk resources folder | 6 | Associated filesystem: "/RESOURCES" |
fk system folder | 100 | |
fk user preferences folder | 0 | 4D folder that stores user preference files within the <userName> directory. |
fk web root folder | 8 | Current Web root folder of the database: if within the package "/PACKAGE/path", otherwise full path |
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.
4D.Folder.new()
履歴
バージョン | 内容 |
---|---|
v18 R6 | 追加 |
4D.Folder.new ( path : Text { ; pathType : Integer }{ ; * } ) : 4D.Folder
4D.Folder.new ( folderConstant : Integer { ; * } ) : 4D.Folder
説明
4D.Folder.new()
関数は、 4D.Folder
型の新しいオブジェクトを作成して返します。 It is identical to the Folder
command (shortcut).
It is recommended to use the
Folder
shortcut command instead of4D.Folder.new()
.
.copyTo()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.copyTo( destinationFolder : 4D.Folder { ; newName : Text } { ; overwrite : Integer } ) : 4D Folder
参照 | タイプ | 説明 | |
---|---|---|---|
destinationFolder | 4D.Folder | -> | 宛先フォルダー |
newName | テキスト | -> | コピー先フォルダーの名前 |
overwrite | 整数 | -> | 既存要素を上書きするには fk overwrite を渡します |
戻り値 | 4D.Folder | <- | コピーされたフォルダー |
説明
.copyTo()
関数は、 Folder
オブジェクトを、destinationFolder 引数で指定したフォルダーへとコピーします。
The destinationFolder must exist on disk, otherwise an error is generated.
By default, the folder is copied with the name of the original folder. If you want to rename the copy, pass the new 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.
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
定数 | 結果 | 説明 |
---|---|---|
fk overwrite | 4 | 既存要素があれば、それを上書きします |
戻り値
コピーされた Folder
オブジェクト。
例題
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+"/Pictures/")
$copiedImages:=$userImages.copyTo(Folder(fk database folder);fk overwrite)
.create()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.create() : Boolean
参照 | タイプ | 説明 | |
---|---|---|---|
戻り値 | ブール | <- | フォルダーが正常に作成された場合には true、それ以外の場合は false |
説明
.create()
関数は、 Folder
オブジェクトのプロパティに基づいてディスク上にフォルダーを作成します。
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.
戻り値
- True if the folder is created successfully;
- False if a folder with the same name already exists or if an error occured.
例題 1
Create an empty folder in the database folder:
var $created : Boolean
$created:=Folder("/PACKAGE/SpecialPrefs").create()
例題 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()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.createAlias( destinationFolder : 4D.Folder ; aliasName : Text { ; aliasType : Integer } ) : 4D.File
参照 | タイプ | 説明 | |
---|---|---|---|
destinationFolder | 4D.Folder | -> | エイリアスまたはショートカットの作成先フォルダー |
aliasName | テキスト | -> | エイリアスまたはショートカットの名称 |
aliasType | 整数 | -> | エイリアスリンクのタイプ |
戻り値 | 4D.File | <- | エイリアスまたはショートカットのフォルダー参照 |
説明
.createAlias()
関数は、destinationFolder オブジェクトで指定されたフォルダー内に、aliasName が指定する名称で、対象フォルダーへの エイリアス (macOS) またはショートカット (Windows) を作成します 。
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:
定数 | 結果 | 説明 |
---|---|---|
fk alias link | 0 | Alias link (default) |
fk symbolic link | 1 | Symbolic link (macOS only) |
On Windows, a shortcut (.lnk file) is always created (the aliasType parameter is ignored).
返されるオブジェクト
A 4D.File
object with the isAlias
property set to true.
例題
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")
.creationDate
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.creationDate : Date
説明
.creationDate
プロパティは、 フォルダーの作成日を返します。
このプロパティは 読み取り専用 です。
.creationTime
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.creationTime : Time
説明
.creationTime
プロパティは、 フォルダーの作成時刻 を返します (00:00 からの経過秒数の形式)。
このプロパティは 読み取り専用 です。
.delete()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.delete( { option : Integer } )
参照 | タイプ | 説明 | |
---|---|---|---|
オプション | 整数 | -> | フォルダー削除のオプション |
説明
.delete()
関数は、 フォルダーを削除します。
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:
定数 | 結果 | 説明 |
---|---|---|
Delete only if empty | 0 | フォルダーが空の場合のみ削除します |
Delete with contents | 1 | フォルダーを中身ごと削除します |
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
GET LAST ERROR STACK
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)
.exists
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.exists : Boolean
説明
.exists
プロパティは、 ディスク上にフォルダーが存在する場合は trueを返します (それ以外の場合は false)。
このプロパティは 読み取り専用 です。
.extension
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.extension : Text
説明
.extension
プロパティは、 フォルダー名の拡張子を返します (あれば)。 An extension always starts with ".". The property returns an empty string if the folder name does not have an extension.
このプロパティは 読み取り専用 です。
.file()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.file( path : Text ) : 4D.File
参照 | タイプ | 説明 | |
---|---|---|---|
path | テキスト | -> | ファイルのPOSIX相対パス名 |
戻り値 | 4D.File | <- | File オブジェクト (無効なパスの場合には null) |
説明
.file()
関数は、 Folder
オブジェクト内に File
オブジェクトを作成し、その参照を返します。
In path, pass a relative POSIX path to designate the file to return. The path will be evaluated from the parent folder as root.
戻り値
File
オブジェクト (無効な path の場合には null)。
例題
var $myPDF : 4D.File
$myPDF:=Folder(fk documents folder).file("Pictures/info.pdf")
.files()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.files( { options : Integer } ) : Collection
参照 | タイプ | 説明 | |
---|---|---|---|
options | 整数 | -> | ファイルリストのオプション |
戻り値 | コレクション | <- | 子ファイルオブジェクトのコレクション |
説明
.files()
関数は、 フォルダーに格納されている File
オブジェクトのコレクションを返します。
Aliases or symbolic links are not resolved.
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:
定数 | 結果 | 説明 |
---|---|---|
fk recursive | 1 | コレクションには、指定フォルダーとそのサブフォルダーのファイル/フォルダーが含まれます |
fk ignore invisible | 8 | 非表示設定のファイルやフォルダーは表示されません |
戻り値
File
オブジェクトのコレクション。
例題 1
You want to know if there are invisible files in the Database folder:
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
例題 2
You want to get all files that are not invisible in the Documents folder:
var $recursive : Collection
$recursive:=Folder(fk documents folder).files(fk recursive+fk ignore invisible)
.folder()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.folder( path : Text ) : 4D.Folder
参照 | タイプ | 説明 | |
---|---|---|---|
path | テキスト | -> | ファイルのPOSIX相対パス名 |
戻り値 | 4D.Folder | <- | 作成された Folder オブジェクト (無効な path の場合には null) |
説明
.folder()
関数は、 親の Folder
オブジェクト内に新しい Folder
オブジェクトを作成し、その参照を返します。
In path, pass a relative POSIX path to designate the folder to return. The path will be evaluated from the parent folder as root.
戻り値
Folder
オブジェクト (無効な path の場合には null)。
例題
var $mypicts : 4D.Folder
$mypicts:=Folder(fk documents folder).folder("Pictures")
.folders()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.folders( { options : Integer } ) : Collection
参照 | タイプ | 説明 | |
---|---|---|---|
options | 整数 | -> | フォルダーリストのオプション |
戻り値 | コレクション | <- | 子フォルダーオブジェクトのコレクション |
説明
.folders()
関数は、 親フォルダーに格納されている 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:
定数 | 結果 | 説明 |
---|---|---|
fk recursive | 1 | コレクションには、指定フォルダーとそのサブフォルダーのファイル/フォルダーが含まれます |
fk ignore invisible | 8 | 非表示設定のファイルやフォルダーは表示されません |
戻り値
Folder
オブジェクトのコレクション。
例題
You want the collection of all folders and subfolders of the database folder:
var $allFolders : Collection
$allFolders:=Folder("/PACKAGE").folders(fk recursive)
.fullName
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.fullName : Text
説明
.fullName
プロパティは、 拡張子 (あれば) を含めたフォルダーの完全な名称を返します。
このプロパティは 読み取り専用 です。
.getIcon()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.getIcon( { size : Integer } ) : Picture
参照 | タイプ | 説明 | |
---|---|---|---|
size | 整数 | -> | 取得するピクチャーの一辺の長さ (ピクセル単位) |
戻り値 | ピクチャー | <- | Icon |
説明
.getIcon()
関数は、 フォルダーのアイコンを返します。
The optional size parameter specifies the dimensions in pixels of the returned icon. This value actually represents the length of the side of the square containing the icon. Icons are usually defined in 32x32 pixels ("large icons") or 16x16 pixels ("small icons"). If you pass 0 or omit this parameter, the "large icon" version is returned.
If the folder does not exist on disk, a default blank icon is returned.
戻り値
フォルダーアイコンの ピクチャー。
.hidden
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.hidden : Boolean
説明
.hidden
プロパティは、 フォルダーがシステムレベルで "非表示" に設定されていれば trueを返します (それ以外の場合は false)。
このプロパティは 読み取り専用 です。
.isAlias
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.isAlias : Boolean
説明
.isAlias
プロパティは、 Folder
オブジェクトに対しては常に falseを返します。
このプロパティは 読み取り専用 です。
.isFile
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.isFile : Boolean
説明
.isFile
プロパティは、 フォルダーに対しては常に falseを返します。
このプロパティは 読み取り専用 です。
.isFolder
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.isFolder : Boolean
説明
.isFolder
プロパティは、 フォルダーに対しては常に trueを返します。
このプロパティは 読み取り専用 です。
.isPackage
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.isPackage : Boolean
説明
.isPackage
プロパティは、 フォルダーが macOS上のパッケージである (かつディスク上に存在している) 場合に trueを返します。 それ以外の場合は false を返します。
Windows 上においては、.isPackage
は常に false を返します。
このプロパティは 読み取り専用 です。
.modificationDate
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.modificationDate : Date
説明
.modificationDate
プロパティは、 フォルダーの最終変更日を返します。
このプロパティは 読み取り専用 です。
.modificationTime
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.modificationTime : Time
説明
.modificationTime
プロパティは、 フォルダーの最終変更時刻 を返します (00:00 からの経過秒数の形式)。
このプロパティは 読み取り専用 です。
.moveTo()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.moveTo( destinationFolder : 4D.Folder { ; newName : Text } ) : 4D.Folder
参照 | タイプ | 説明 | |
---|---|---|---|
destinationFolder | 4D.Folder | -> | 宛先フォルダー |
newName | テキスト | -> | 移動先でのフォルダーの完全な名称 |
戻り値 | 4D.Folder | <- | 移動したフォルダー |
説明
.moveTo( )
関数は、 Folder
オブジェクト (ソースフォルダー) を destinationFolder が指定する移行先へと移動すると同時に、newName を指定した場合は名称も変更します。
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.
返されるオブジェクト
The moved Folder
object.
例題
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")
.name
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.name : Text
説明
.name
プロパティは、 拡張子 (あれば) を含まないフォルダー名を返します。
このプロパティは 読み取り専用 です。
.original
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.original : 4D.Folder
説明
.original
プロパティは、 対象フォルダーと同じフォルダーオブジェクトを返します。
このプロパティは 読み取り専用 です。
This property is available on folders to allow generic code to process folders or files.
.parent
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.parent : 4D.Folder
説明
.parent
プロパティは、 対象フォルダーの親フォルダーオブジェクトを返します。 If the path represents a system path (e.g., "/DATA/"), the system path is returned.
If the folder does not have a parent (root), the null value is returned.
このプロパティは 読み取り専用 です。
.path
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.path : Text
説明
.path
プロパティは、 フォルダーの POSIXパスを返します。 If the path represents a filesystem (e.g., "/DATA/"), the filesystem is returned.
このプロパティは 読み取り専用 です。
.platformPath
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.platformPath : Text
説明
.platformPath
プロパティは、 カレントプラットフォームのシンタックスで表現されたフォルダーのパスを返します。
このプロパティは 読み取り専用 です。
.rename()
履歴
バージョン | 内容 |
---|---|
v17 R5 | 追加 |
.rename( newName : Text ) : 4D.Folder
参照 | タイプ | 説明 | |
---|---|---|---|
newName | テキスト | -> | フォルダーの新しい完全な名称 |
戻り値 | 4D.Folder | <- | 名称変更されたフォルダー |
説明
.rename()
関数は、 フォルダー名を newName に指定した名称に変更し、名称変更後の Folder
オブジェクトを返します。
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.
返されるオブジェクト
名称変更された Folder
オブジェクト。
例題
var $toRename : 4D.Folder
$toRename:=Folder("/RESOURCES/Pictures").rename("Images")