infinity.directory¶
Provides directory manipulation and examination functionality.
Module: infinity.fileSystem
Example:
infinity.loadModule('infinity.fileSystem');
if(!infinity.directory.exists('testDir')){
infinity.directory.create('testDir/testDir2');
console.debug(infinity.directory.list('testDir', '*', 0));
//["testDir/testDir2"]
infinity.directory.move('testDir/testDir2', 'testDir2');
infinity.directory.remove('testDir2');
console.debug(infinity.directory.list('./', '*', 0));
//["./testDir"]
infinity.directory.remove('testDir');
}
stringArray¶
Extends: Array<string>
An array of strings.
create()¶
Creates a directory with the specified name, including all missing parent directories. Returns true if the directory was created or already exists, otherwise false.
Signature:
create( directory: string ): boolean
Parameters:
- directory:
stringThe name of the directory to be created.
Return type: boolean
Example:
infinity.loadModule('infinity.fileSystem');
if ( infinity.directory.create(directory) ) {
//...
}
exists()¶
Indicates whether a directory with the specified name exists.
Signature:
exists( directory: string ): boolean
Parameters:
- directory:
stringThe name of the directory to be checked for.
Return type: boolean
Example:
infinity.loadModule('infinity.fileSystem');
if ( infinity.directory.exists(directory) ) {
//...
}
freeSpace()¶
Returns the number of free bytes on the volume containing the specified path that are available to the current process (respecting disk quotas; like the "Available" column of df). Returns -1 if the value cannot be determined (e.g. because the path does not exist).
Signature:
freeSpace( directory: string ): number
Parameters:
- directory:
stringA path on the volume to examine.
Return type: number
Example:
infinity.loadModule('infinity.fileSystem');
let free = infinity.directory.freeSpace(infinity.current.root);
if ( free >= 0 && free < 1024 * 1024 * 1024 ) {
console.warn('Less than 1 GB free disk space');
}
list()¶
Returns a infinity.directory.stringArray of contents of the specified directory (not recursive). Each entry is the given directory path followed by the entry's name, using / as path delimiter. Shows only files that are not hidden, system, read-only or symbolic links by default, but can be adjusted otherwise through the filter parameter. The entries . and .. are never returned.
Signature:
list( directory: string, mask?: string, filter?: infinity.directory.filter ): infinity.directory.stringArray
Parameters:
-
directory:
stringThe directory to look in.
-
mask:
string, optionalA search mask with wildcards (
*,?), e.g.'*.txt'. Default:'*'. -
filter: infinity.directory.filter, optional
A combination of infinity.directory.filter flags, allowing to specify the type of elements to search for. Default:
infinity.directory.filter.files.
Return type: infinity.directory.stringArray
Example:
infinity.loadModule('infinity.fileSystem');
let directories = infinity.directory.list('c:/', '*',infinity.directory.filter.files | infinity.directory.filter.directories);
console.debug(directories);
move()¶
Moves all files and subdirectories of the source directory into the target directory and then removes the source directory. The target directory (including missing parent directories) is created if necessary; existing files in it are overwritten. Returns false if the target directory could not be created or any element could not be moved.
Signature:
move( srcDirectory: string, dstDirectory: string ): boolean
Parameters:
-
srcDirectory:
stringThe path to the source directory.
-
dstDirectory:
stringThe path to the target directory, which receives the contents of the source directory. To keep the name of the source directory, include it at the end of this path.
Return type: boolean
Example:
infinity.loadModule('infinity.fileSystem');
if ( infinity.directory.move('c:/tmp/toBeMoved', 'c:/tmp/toHold/toBeMoved') ) {
//...
}
remove()¶
Removes the specified directory, if it is empty (or including its contents, if recursive is true). Returns false if the directory does not exist or could not be removed.
Signature:
remove( directory: string, recursive?: boolean ): boolean
Parameters:
-
directory:
stringThe path of the directory to remove. If the directory has contents, it will not be deleted and the function will return
false, unless the parameterrecursiveis set totrue. -
recursive:
boolean, optionalWhether to remove the directory and all its contents, including any subdirectories and files. Default:
false.
Return type: boolean
Example:
infinity.loadModule('infinity.fileSystem');
if ( infinity.directory.remove('c:/tmp/toBeDeleted/') ) {
//...
}
totalSpace()¶
Returns the total size in bytes of the volume containing the specified path. Returns -1 if the value cannot be determined (e.g. because the path does not exist).
Signature:
totalSpace( directory: string ): number
Parameters:
- directory:
stringA path on the volume to examine.
Return type: number
Example:
infinity.loadModule('infinity.fileSystem');
let total = infinity.directory.totalSpace(infinity.current.root);
let free = infinity.directory.freeSpace(infinity.current.root);
if ( total > 0 && free >= 0 ) {
console.debug('Disk usage: ' + Math.round((total - free) / total * 100) + '%');
}
infinity.directory.filter¶
Flags for list(), combinable with |. files and directories select the element types to return. hidden, system, readOnly and symLink don't restrict the result to such elements, but additionally include them; without these flags, such elements are excluded.
Values:
-
none:
0No filter (show all elements, including hidden, system, read-only elements and symbolic links).
-
files:
1Include files.
-
directories:
2Include directories.
-
hidden:
4Include hidden elements.
-
system:
8Include system elements.
-
readOnly:
16Include read-only elements.
-
symLink:
32Include symbolic links.
Example:
infinity.loadModule('infinity.fileSystem');
let filter = infinity.directory.filter.files | infinity.directory.filter.directories;