Skip to content

infinity.directory

Provides directory manipulation and examination functionality.

Module: infinity.fileSystem

Interfaces:
Functions:
Enums:

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');
}

Interfaces

stringArray

Extends: Array<string>

An array of strings.


Functions

create()

Creates a directory with the specified name. Returns a boolean value according to success or failure.

Signature:

create( directory: string ): boolean

Parameters:

  • directory: string

    The 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: string

    The name of the directory to be checked for.

Return type: boolean

Example:

infinity.loadModule('infinity.fileSystem');
if ( infinity.directory.exists(directory) ) {
  //...
}

list()

Returns a infinity.directory.stringArray of contents of the specified directory. Shows only files by default but can be adjusted otherwise through the filter parameter.

Signature:

list( directory: string, mask?: string, filter?: infinity.directory.filter ): infinity.directory.stringArray

Parameters:

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 the specified directory or its contents to the specified location.

Signature:

move( srcDirectory: string, dstDirectory: string ): boolean

Parameters:

  • srcDirectory: string

    The path to the source directory.

  • dstDirectory: string

    The path to the target directory. Will receive the contents of the source directory, unless the name of the source directory is as well specified inside 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.

Signature:

remove( directory: string, recursive?: boolean ): boolean

Parameters:

  • directory: string

    The path of the directory to remove. If the directory has contents, it will not be deleted and the function will return false, unless the parameter recursive is set to true.

  • recursive: boolean, optional

    Whether to remove the directory and all its contents, including any subdirectories and files.

Return type: boolean

Example:

infinity.loadModule('infinity.fileSystem');
if ( infinity.directory.remove('c:/tmp/toBeDeleted/') ) {
  //...
}

Enums

infinity.directory.filter

Values:

  • none: 0

    No filter (show all).

  • files: 1

    To show only files.

  • directories: 2

    To show only directories.

  • hidden: 4

    To show only hidden elements.

  • system: 8

    To show only system elements.

  • readOnly: 16

    To show only read-only elements.

  • symLink: 32

    To show only symbolic links.

Example:

infinity.loadModule('infinity.fileSystem');
let filter = infinity.directory.filter.files | infinity.directory.filter.directories;