Skip to main content

File

Helper functions for file operations.

Functions

copyFileOrDirectory()

function copyFileOrDirectory(srcPath, dstPath): void

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

ParameterType
srcPathstring
dstPathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:20


copyFileOrDirectoryAsync()

function copyFileOrDirectoryAsync(srcPath, dstPath): Promise<void>

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

ParameterType
srcPathstring
dstPathstring

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/file.ts:38


cp()

function cp(srcPath, dstPath): void

Alias for the copyFileOrDirectory function. Intended to be used in scripts.

Parameters

ParameterType
srcPathstring
dstPathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:54


deleteFileOrDirectory()

function deleteFileOrDirectory(...filePaths): void

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

ParameterType
...filePathsreadonly string[]

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:67


fileOrDirectoryExists()

function fileOrDirectoryExists(filePath): boolean

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

ParameterType
filePathstring

Returns

boolean

Defined in

packages/complete-node/src/functions/file.ts:88


getFileNamesInDirectory()

function getFileNamesInDirectory(directoryPath, filter?): readonly string[]

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

ParameterTypeDescription
directoryPathstringThe path to the directory.
filter?"files" | "directories"Optional. If specified, will only return this type of file.

Returns

readonly string[]

Defined in

packages/complete-node/src/functions/file.ts:111


getFileNamesInDirectoryAsync()

function getFileNamesInDirectoryAsync(directoryPath, filter?): Promise<readonly string[]>

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

ParameterTypeDescription
directoryPathstringThe path to the directory.
filter?"files" | "directories"Optional. If specified, will only return this type of file.

Returns

Promise<readonly string[]>

Defined in

packages/complete-node/src/functions/file.ts:138


getFilePath()

function getFilePath(fileName, filePathOrDirPath): string

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

ParameterTypeDescription
fileNamestringThe name of the file to find.
filePathOrDirPathundefined | stringEither 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

Defined in

packages/complete-node/src/functions/file.ts:197


getFilePathAsync()

function getFilePathAsync(fileName, filePathOrDirPath): Promise<string>

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

ParameterTypeDescription
fileNamestringThe name of the file to find.
filePathOrDirPathundefined | stringEither 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>

Defined in

packages/complete-node/src/functions/file.ts:236


getFilePathsInDirectory()

function getFilePathsInDirectory(directoryPath, filter?): readonly string[]

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

ParameterTypeDescription
directoryPathstringThe path to the directory.
filter?"files" | "directories"Optional. If specified, will only return this type of file.

Returns

readonly string[]

Defined in

packages/complete-node/src/functions/file.ts:276


getFilePathsInDirectoryAsync()

function getFilePathsInDirectoryAsync(directoryPath, filter?): Promise<readonly string[]>

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

ParameterTypeDescription
directoryPathstringThe path to the directory.
filter?"files" | "directories"Optional. If specified, will only return this type of file.

Returns

Promise<readonly string[]>

Defined in

packages/complete-node/src/functions/file.ts:293


getMatchingFilePaths()

function getMatchingFilePaths(directoryPath, matchFunc): Promise<readonly string[]>

Helper function to recursively traverse a directory and get the file names that match the provided logic.

Parameters

ParameterTypeDescription
directoryPathstringThe path to the directory to crawl.
matchFunc(filePath) => booleanThe function that contains the matching logic.

Returns

Promise<readonly string[]>

Defined in

packages/complete-node/src/functions/file.ts:308


isDirectory()

function isDirectory(filePath): boolean

Helper function to synchronously check if the provided path exists and is a directory.

Parameters

ParameterType
filePathstring

Returns

boolean

Defined in

packages/complete-node/src/functions/file.ts:339


isDirectoryAsync()

function isDirectoryAsync(filePath): Promise<boolean>

Helper function to asynchronously check if the provided path exists and is a directory.

Parameters

ParameterType
filePathstring

Returns

Promise<boolean>

Defined in

packages/complete-node/src/functions/file.ts:348


isFile()

function isFile(filePath): boolean

Helper function to synchronously check if the provided path exists and is a file.

Parameters

ParameterType
filePathstring

Returns

boolean

Defined in

packages/complete-node/src/functions/file.ts:358


isFileAsync()

function isFileAsync(filePath): Promise<boolean>

Helper function to asynchronously check if the provided path exists and is a file.

Parameters

ParameterType
filePathstring

Returns

Promise<boolean>

Defined in

packages/complete-node/src/functions/file.ts:367


function isLink(filePath): boolean

Helper function to synchronously check if the provided path exists and is a symbolic link.

Parameters

ParameterType
filePathstring

Returns

boolean

Defined in

packages/complete-node/src/functions/file.ts:377


isSubdirectoryOf()

function isSubdirectoryOf(directoryPath, parentPath): boolean

Helper function to see if a directory is a subdirectory of another one.

Parameters

ParameterType
directoryPathstring
parentPathstring

Returns

boolean

Defined in

packages/complete-node/src/functions/file.ts:386


makeDirectory()

function makeDirectory(directoryPath): void

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

ParameterType
directoryPathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:404


mkdir()

function mkdir(directoryPath): void

Alias for the makeDirectory function. Intended to be used in scripts.

Parameters

ParameterType
directoryPathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:417


moveAllFilesInDirectory()

function moveAllFilesInDirectory(srcDirectory, dstDirectory): void

Helper function to move all files from one directory to another one.

Parameters

ParameterType
srcDirectorystring
dstDirectorystring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:422


moveFile()

function moveFile(srcPath, dstPath): void

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

ParameterType
srcPathstring
dstPathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:442


mv()

function mv(srcPath, dstPath): void

Alias for the moveFile function. Intended to be used in scripts.

Parameters

ParameterType
srcPathstring
dstPathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:447


renameFile()

function renameFile(srcPath, dstPath): void

Helper function to synchronously rename a file.

This will throw an error if the file cannot be renamed.

Parameters

ParameterType
srcPathstring
dstPathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:456


renameFileExtensions()

function renameFileExtensions(
directoryPath,
srcFileExtension,
dstFileExtension): Promise<void>

Helper function to recursively rename all of the files in a directory from one file extension to another.

Parameters

ParameterTypeDescription
directoryPathstringThe path to the directory to crawl.
srcFileExtensionstringThe file extension to change from. Do not include a period in the string.
dstFileExtensionstringThe file extension to change to. Do not include a period in the string.

Returns

Promise<void>

Defined in

packages/complete-node/src/functions/file.ts:472


rm()

function rm(...filePaths): void

Alias for the deleteFileOrDirectory function. Intended to be used in scripts.

Parameters

ParameterType
...filePathsreadonly string[]

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:500


touch()

function touch(filePath): void

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

ParameterType
filePathstring

Returns

void

Defined in

packages/complete-node/src/functions/file.ts:509