Directory
Description
Represents a directory on disk that can be watched for changes.
API documentation
Construction
::constructor(directoryPath, symlink)
Configures a new Directory instance, no files are accessed.
| Argument | Description |
|---|---|
directoryPath
|
A String containing the absolute path to the directory |
symlink
|
optional
A Boolean indicating if the path is a symlink. (default: false) |
::create(mode)
Creates the directory on disk that corresponds to ::getPath() if
no such directory already exists.
| Argument | Description |
|---|---|
mode
|
optional
Number that defaults to |
Return values
-
Returns a Promise that resolves once the directory is created on disk. It resolves to a boolean value that is true if the directory was created or false if it already existed.
Event Subscription
::onDidChange(callback)
Invoke the given callback when the directory's contents change.
| Argument | Description |
|---|---|
callback
|
Function to be called when the directory's contents change. |
Return values
-
Returns a Disposable on which
.dispose()can be called to unsubscribe.
Directory Metadata
::isFile()
Return values
-
Returns a Boolean, always false.
::isDirectory()
Return values
-
Returns a Boolean, always true.
::isSymbolicLink()
Return values
-
Returns a Boolean indicating whether or not this is a symbolic link
::exists()
Return values
-
Returns a promise that resolves to a Boolean, true if the directory exists, false otherwise.
::existsSync()
Return values
-
Returns a Boolean, true if the directory exists, false otherwise.
::isRoot()
Managing Paths
::getPath()
This may include unfollowed symlinks or relative directory entries. Or it may be fully resolved, it depends on what you give it.
Return values
-
Returns the directory's String path.
::getRealPathSync()
All relative directory entries are removed and symlinks are resolved to their final destination.
Return values
-
Returns this directory's completely resolved String path.
::getBaseName()
Return values
-
Returns the String basename of the directory.
::relativize()
Return values
-
Returns the relative String path to the given path from this directory.
Traversing
::getParent()
Traverse to the parent directory.
Return values
-
Returns a Directory.
::getFile(filename)
Traverse within this Directory to a child File. This method doesn't actually check to see if the File exists, it just creates the File object.
| Argument | Description |
|---|---|
filename
|
The String name of a File within this Directory. |
Return values
-
Returns a File.
::getSubdirectory(dirname)
Traverse within this a Directory to a child Directory. This method doesn't actually check to see if the Directory exists, it just creates the Directory object.
| Argument | Description |
|---|---|
dirname
|
The String name of the child Directory. |
Return values
-
Returns a Directory.
::getEntriesSync()
Reads file entries in this directory from disk synchronously.
Return values
::getEntries(callback)
Reads file entries in this directory from disk asynchronously.
| Argument | Description |
|---|---|
callback
|
A Function to call with the following arguments: |
error
|
An Error, may be null. |
entries
|
::contains(pathToCheck)
Determines if the given path (real or symbolic) is inside this directory. This method does not actually check if the path exists, it just checks if the path is under this directory.
| Argument | Description |
|---|---|
pathToCheck
|
The String path to check. |
Return values
-
Returns a Boolean whether the given path is inside this directory.