File
Helper functions for file operations.
Functions
copyFileOrDirectory()
function copyFileOrDirectory(srcPath, dstPath): void
Defined in: functions/file.ts:20
Helper function to synchronously copy a file or directory. If a path to a directory is specified, the directory will be recursively copied.
This will throw an error if the file cannot be copied.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
void
copyFileOrDirectoryAsync()
function copyFileOrDirectoryAsync(srcPath, dstPath): Promise<void>
Defined in: functions/file.ts:38
Helper function to asynchronously copy a file or directory. If a path to a directory is specified, the directory will be recursively copied.
This will throw an error if the file cannot be copied.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
Promise
<void
>
cp()
function cp(srcPath, dstPath): void
Defined in: functions/file.ts:54
Alias for the copyFileOrDirectory
function. Intended to be used in scripts.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
void
deleteFileOrDirectory()
function deleteFileOrDirectory(...filePaths): void
Defined in: functions/file.ts:67
Helper function to synchronously 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 will throw an error if the file cannot be deleted.
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
void
fileOrDirectoryExists()
function fileOrDirectoryExists(filePath): boolean
Defined in: functions/file.ts:88
Helper function to synchronously check if a file exists.
This will throw an error if there is an error when checking the file path.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
boolean
getFileNamesInDirectory()
function getFileNamesInDirectory(directoryPath, filter?): readonly string[]
Defined in: functions/file.ts:111
Helper function to synchronously get the file names inside of a directory. (If the full path is
required, use the getFilePathsInDirectory
helper function instead.)
This will throw an error if there is an error when checking the directory.
Parameters
Parameter | Type | Description |
---|---|---|
directoryPath | string | The path to the directory. |
filter ? | "files" | "directories" | Optional. If specified, will only return this type of file. |
Returns
readonly string
[]
getFileNamesInDirectoryAsync()
function getFileNamesInDirectoryAsync(directoryPath, filter?): Promise<readonly string[]>
Defined in: functions/file.ts:138
Helper function to asynchronously get the file names inside of a directory. (If the full path is required, you must manually join the file name with the path to the directory.)
This will throw an error if there is an error when checking the directory.
Parameters
Parameter | Type | Description |
---|---|---|
directoryPath | string | The path to the directory. |
filter ? | "files" | "directories" | Optional. If specified, will only return this type of file. |
Returns
Promise
<readonly string
[]>
getFilePath()
function getFilePath(fileName, filePathOrDirPath): string
Defined in: functions/file.ts:197
Helper function to synchronously get the path to file, given either a file path, a directory
path, or undefined
.
This will throw an error if the file cannot be found.
Parameters
Parameter | Type | Description |
---|---|---|
fileName | string | The name of the file to find. |
filePathOrDirPath | undefined | string | 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
string
getFilePathAsync()
function getFilePathAsync(fileName, filePathOrDirPath): Promise<string>
Defined in: functions/file.ts:236
Helper function to asynchronously get the path to file, given either a file path, a directory
path, or undefined
.
This will throw an error if the file cannot be found.
Parameters
Parameter | Type | Description |
---|---|---|
fileName | string | The name of the file to find. |
filePathOrDirPath | undefined | string | 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
>
getFilePathsInDirectory()
function getFilePathsInDirectory(directoryPath, filter?): readonly string[]
Defined in: functions/file.ts:276
Helper function to synchronously get the file names inside of a directory.
This will throw an error if there is an error when checking the directory.
Parameters
Parameter | Type | Description |
---|---|---|
directoryPath | string | The path to the directory. |
filter ? | "files" | "directories" | Optional. If specified, will only return this type of file. |
Returns
readonly string
[]
getFilePathsInDirectoryAsync()
function getFilePathsInDirectoryAsync(directoryPath, filter?): Promise<readonly string[]>
Defined in: functions/file.ts:293
Helper function to asynchronously get the file names inside of a directory.
This will throw an error if there is an error when checking the directory.
Parameters
Parameter | Type | Description |
---|---|---|
directoryPath | string | The path to the directory. |
filter ? | "files" | "directories" | Optional. If specified, will only return this type of file. |
Returns
Promise
<readonly string
[]>
getMatchingFilePaths()
function getMatchingFilePaths(directoryPath, matchFunc): Promise<readonly string[]>
Defined in: functions/file.ts:308
Helper function to recursively traverse a directory and get the file names that match the provided logic.
Parameters
Parameter | Type | Description |
---|---|---|
directoryPath | string | The path to the directory to crawl. |
matchFunc | (filePath ) => boolean | The function that contains the matching logic. |
Returns
Promise
<readonly string
[]>
isDirectory()
function isDirectory(filePath): boolean
Defined in: functions/file.ts:339
Helper function to synchronously check if the provided path exists and is a directory.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
boolean
isDirectoryAsync()
function isDirectoryAsync(filePath): Promise<boolean>
Defined in: functions/file.ts:348
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): boolean
Defined in: functions/file.ts:358
Helper function to synchronously check if the provided path exists and is a file.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
boolean
isFileAsync()
function isFileAsync(filePath): Promise<boolean>
Defined in: functions/file.ts:367
Helper function to asynchronously check if the provided path exists and is a file.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
Promise
<boolean
>
isLink()
function isLink(filePath): boolean
Defined in: functions/file.ts:377
Helper function to synchronously check if the provided path exists and is a symbolic link.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
boolean
isSubdirectoryOf()
function isSubdirectoryOf(directoryPath, parentPath): boolean
Defined in: functions/file.ts:386
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): void
Defined in: functions/file.ts:404
Helper function to synchronously make a new directory. Will recursively make as many subdirectories as needed.
If the recursive behavior is not desired, then use fs.mkdirSync
directly.
This will throw an error if the directory cannot be created.
Parameters
Parameter | Type |
---|---|
directoryPath | string |
Returns
void
mkdir()
function mkdir(directoryPath): void
Defined in: functions/file.ts:417
Alias for the makeDirectory
function. Intended to be used in scripts.
Parameters
Parameter | Type |
---|---|
directoryPath | string |
Returns
void
moveAllFilesInDirectory()
function moveAllFilesInDirectory(srcDirectory, dstDirectory): void
Defined in: functions/file.ts:422
Helper function to move all files from one directory to another one.
Parameters
Parameter | Type |
---|---|
srcDirectory | string |
dstDirectory | string |
Returns
void
moveFile()
function moveFile(srcPath, dstPath): void
Defined in: functions/file.ts:442
Helper function to synchronously move a file.
This will throw an error if the file cannot be moved.
(This is simply an alias for the renameFile
function, since the Node.js API uses the same thing
for both operations.)
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
void
mv()
function mv(srcPath, dstPath): void
Defined in: functions/file.ts:447
Alias for the moveFile
function. Intended to be used in scripts.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
void
renameFile()
function renameFile(srcPath, dstPath): void
Defined in: functions/file.ts:456
Helper function to synchronously rename a file.
This will throw an error if the file cannot be renamed.
Parameters
Parameter | Type |
---|---|
srcPath | string |
dstPath | string |
Returns
void
renameFileExtensions()
function renameFileExtensions(
directoryPath,
srcFileExtension,
dstFileExtension): Promise<void>
Defined in: functions/file.ts:472
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
>
rm()
function rm(...filePaths): void
Defined in: functions/file.ts:500
Alias for the deleteFileOrDirectory
function. Intended to be used in scripts.
Parameters
Parameter | Type |
---|---|
...filePaths | readonly string [] |
Returns
void
touch()
function touch(filePath): void
Defined in: functions/file.ts:509
Helper function to synchronously write 0 bytes to a file, similar to the touch
command.
This will throw an error if the file cannot be written to.
Parameters
Parameter | Type |
---|---|
filePath | string |
Returns
void