File
Helper functions for file operations.
Functions
copyFileOrDirectory()
function copyFileOrDirectory(srcPath, dstPath): Promise<void>;
Defined in: functions/file.ts:22
Helper function to asynchronously copy a file or directory. If a path to a directory is specified, the directory will be recursively copied.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
Promise
<void
>
Throws
If the file cannot be copied.
cp()
function cp(srcPath, dstPath): Promise<void>;
Defined in: functions/file.ts:48
Helper function to asynchronously copy a file or directory. If a path to a directory is specified, the directory will be recursively copied.
This is an alias for the copyFileOrDirectory
function. (It is intended to be used in scripts.)
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
Promise
<void
>
Throws
If the file cannot be copied.
deleteFileOrDirectory()
function deleteFileOrDirectory(...filePaths): Promise<void>;
Defined in: functions/file.ts:61
Helper function to asynchronously delete a file or directory. If a path to a directory is specified, the directory will be recursively deleted. If the path does not exist, this function will be a no-op.
This function is variadic, meaning that you can pass as many file paths as you want to delete.
Parameters
Parameter | Type |
---|---|
...filePaths | readonly string [] |
Returns
Promise
<void
>
Throws
If the file cannot be deleted.
exists()
function exists(filePath): Promise<boolean>;
Defined in: functions/file.ts:89
Helper function to see if the given file path exists. This will work with files, directories, links, and so on.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
Promise
<boolean
>
getDirectoryHashSHA1()
function getDirectoryHashSHA1(directoryPath): Promise<string>;
Defined in: functions/file.ts:106
Helper function to get a SHA1 hash for every file in a directory. (This function correctly handles nested subdirectories.)
This is useful to see if the contents of a directory have changed in any way.
Parameters
Parameter | Type |
---|---|
directoryPath | string |
Returns
Promise
<string
>
Throws
If there is an error when checking the directory.
getFileHashSHA1()
function getFileHashSHA1(filePath): Promise<string>;
Defined in: functions/file.ts:131
Helper function to get the SHA1 hash of a file.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
Promise
<string
>
Throws
If there is an error when reading the file.
getFileNamesInDirectory()
function getFileNamesInDirectory(
directoryPath,
filter?,
recursive?,
paths?): Promise<readonly string[]>;
Defined in: functions/file.ts:155
Helper function to asynchronously get the file names or file paths inside of a directory.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
directoryPath | string | undefined | The path to the directory. |
filter? | "files" | "directories" | undefined | Optional. If specified, will only return this type of file. |
recursive? | boolean | false | Optional. If true, will include files in all subdirectories. Default is false. |
paths? | boolean | false | Optional. If true, will return the full file paths instead of just the file names. Default is false. |
Returns
Promise
<readonly string
[]>
Throws
If there is an error when checking the directory.
getFilePath()
function getFilePath(fileName, filePathOrDirPath): Promise<string>;
Defined in: functions/file.ts:214
Helper function to synchronously get the path to file, given either a file path, a directory
path, or undefined
.
Parameters
Parameter | Type | Description |
---|---|---|
fileName | string | The name of the file to find. |
filePathOrDirPath | string | undefined | Either the path to a file or the path to a directory which contains the file. If undefined is passed, the current working directory will be used. |
Returns
Promise
<string
>
Throws
If the file cannot be found.
getFilePathsInDirectory()
function getFilePathsInDirectory(
directoryPath,
filter?,
recursive?): Promise<readonly string[]>;
Defined in: functions/file.ts:252
Helper function to asynchronously get the file paths inside of a directory.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
directoryPath | string | undefined | The path to the directory. |
filter? | "files" | "directories" | undefined | Optional. If specified, will only return this type of file. Defaults to returning both files and directories. |
recursive? | boolean | false | Optional. If true, will include files in all subdirectories. Default is false. |
Returns
Promise
<readonly string
[]>
Throws
If there is an error when checking the directory.
isDirectory()
function isDirectory(filePath): Promise<boolean>;
Defined in: functions/file.ts:261
Helper function to asynchronously check if the provided path exists and is a directory.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
Promise
<boolean
>
isFile()
function isFile(filePath): Promise<boolean>;
Defined in: functions/file.ts:271
Helper function to asynchronously check if the provided path exists and is a file.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
Promise
<boolean
>
isFileSystemRootDirectory()
function isFileSystemRootDirectory(directoryPath): boolean;
Defined in: functions/file.ts:285
Helper function to see if a directory is the root directory of the file system.
Under the hood, this uses path.normalize
and path.dirname
to determine this.
Parameters
Parameter | Type |
---|---|
directoryPath | string |
Returns
boolean
isLink()
function isLink(filePath): Promise<boolean>;
Defined in: functions/file.ts:293
Helper function to asynchronously check if the provided path exists and is a symbolic link.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
Promise
<boolean
>
isSubdirectoryOf()
function isSubdirectoryOf(directoryPath, parentPath): boolean;
Defined in: functions/file.ts:303
Helper function to see if a directory is a subdirectory of another one.
Parameters
Parameter | Type |
---|---|
directoryPath | string |
parentPath | string |
Returns
boolean
makeDirectory()
function makeDirectory(directoryPath, recursive): Promise<void>;
Defined in: functions/file.ts:321
Helper function to asynchronously make a new directory. By default, it will recursively make as many subdirectories as needed. If the directory already exists, this function will be a no-op.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
directoryPath | string | undefined | The path to the directory to create. |
recursive | boolean | true | Optional. Default is true. |
Returns
Promise
<void
>
Throws
If the directory cannot be created.
mkdir()
function mkdir(directoryPath, recursive): Promise<void>;
Defined in: functions/file.ts:346
Helper function to asynchronously make a new directory. By default, it will recursively make as many subdirectories as needed. If the directory already exists, this function will be a no-op.
This is an alias for the makeDirectory
function. (It is intended to be used in scripts.)
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
directoryPath | string | undefined | The path to the directory to create. |
recursive | boolean | true | Optional. Default is true. |
Returns
Promise
<void
>
Throws
If the directory cannot be created.
moveAllFilesInDirectory()
function moveAllFilesInDirectory(srcDirectory, dstDirectory): Promise<void>;
Defined in: functions/file.ts:358
Helper function to move all files from one directory to another one.
Parameters
Parameter | Type |
---|---|
srcDirectory | string |
dstDirectory | string |
Returns
Promise
<void
>
Throws
If a file cannot be moved.
moveFileOrDirectory()
function moveFileOrDirectory(srcPath, dstPath): Promise<void>;
Defined in: functions/file.ts:380
Helper function to asynchronously move a file or directory.
This is an alias for the renameFileOrDirectory
function, since the Node.js API uses the same
thing for both operations.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
Promise
<void
>
Throws
If the file cannot be moved.
mv()
function mv(srcPath, dstPath): Promise<void>;
Defined in: functions/file.ts:394
Helper function to asynchronously move a file or directory.
This is an alias for the moveFileOrDirectory
function. (It is intended to be used in scripts.)
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
Promise
<void
>
Throws
If the file cannot be moved.
renameFileExtensions()
function renameFileExtensions(
directoryPath,
srcFileExtension,
dstFileExtension): Promise<void>;
Defined in: functions/file.ts:407
Helper function to recursively rename all of the files in a directory from one file extension to another.
Parameters
Parameter | Type | Description |
---|---|---|
directoryPath | string | The path to the directory to crawl. |
srcFileExtension | string | The file extension to change from. Do not include a period in the string. |
dstFileExtension | string | The file extension to change to. Do not include a period in the string. |
Returns
Promise
<void
>
Throws
If a file cannot be renamed.
renameFileOrDirectory()
function renameFileOrDirectory(srcPath, dstPath): Promise<void>;
Defined in: functions/file.ts:439
Helper function to asynchronously rename a file. Since renames are not allowed across file system boundaries, this will automatically handle that special case by performing a copy and delete operation instead.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
Promise
<void
>
Throws
If the file cannot be renamed.
rm()
function rm(...filePaths): Promise<void>;
Defined in: functions/file.ts:479
Helper function to asynchronously delete a file or directory. If a path to a directory is specified, the directory will be recursively deleted. If the path does not exist, this function will be a no-op.
This function is variadic, meaning that you can pass as many file paths as you want to delete.
This is an alias for the deleteFileOrDirectory
function. (It is intended to be used in
scripts.)
Parameters
Parameter | Type |
---|---|
...filePaths | readonly string [] |
Returns
Promise
<void
>
Throws
If the file cannot be deleted.
touch()
function touch(filePath): Promise<void>;
Defined in: functions/file.ts:488
Helper function to asynchronously write 0 bytes to a file, similar to the touch
command.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
Promise
<void
>
Throws
If the file cannot be touched.