Directory

Directory

Abstract representation of a directory, with methods for traversal and pattern generation.

Constructor

new Directory(path)

Source:
Parameters:
Name Type Description
path String The path represented by this directory.

Members

absolutePath :String

Source:
Returns the absolute path to this directory.
Type:
  • String

name :String

Source:
Returns the name of the directory.
Type:
  • String

path

Source:
Returns the relative path to this directory.

Methods

(static) createTree(rootPath, tree) → {Directory}

Source:
Creates a folder tree based on an object that describes the tree structure.
Parameters:
Name Type Description
rootPath String A string that represents the path to the root directory of the tree.
tree Object An object representation of the tree structure.
Returns:
A directory object that represents the root of the tree.
Type
Directory

(static) traverseTree(root, callback)

Source:
Traverses a directory tree, invoking the callback function at each level of the tree.
Parameters:
Name Type Description
root Directory The root level of the tree to traverse.
callback function The callback function that is invoked as each directory is traversed.

addChild(name)

Source:
Adds a child directory object to the current directory.
Parameters:
Name Type Description
name String Name of the child directory.

getAllFilesPattern(extensionopt)

Source:
Gets a string glob that can be used to match all folders/files in the current folder and all sub folders, optionally filtered by file extension.
Parameters:
Name Type Attributes Description
extension String <optional>
An optional extension to use when generating a globbing pattern.

getChild(path) → {Directory}

Source:
Retrieves a child directory object by recursively searching through the current directory's child tree.
Parameters:
Name Type Description
path String The relative path to the child directory, with each path element separated by "/".
Returns:
A directory reference for the specified child. If a child is not found at the specified path, an error will be thrown.
Type
Directory

getChildren() → {Array.<Directory>}

Source:
Returns an array containing all first level children of the current directory.
Returns:
An array of first level children for the directory.
Type
Array.<Directory>

getFilePath(fileName) → {String}

Source:
Returns the path to a file within the specified directory. This file does not have to actually exist on the file system.
Parameters:
Name Type Description
fileName String The name of the file.
Returns:
The path to the file including the current directory path.
Type
String