fs
unlink
¶
Deletes a file if it exists.
Parameters
Name | Type | Description |
---|---|---|
path |
string | The path to the file to delete. |
Returns: {void}
exists
¶
Checks if a file or directory exists.
Parameters
Name | Type | Description |
---|---|---|
path |
string | The path to the file or directory to check. |
Returns: {boolean}
trueif the file or directory exists,
falseotherwise.
isFile
¶
Checks if a path is a file.
Parameters
Name | Type | Description |
---|---|---|
path |
any | the |
Returns: true if the path is a file
isDirectory
¶
Checks if a path is a directory.
Parameters
Name | Type | Description |
---|---|---|
path |
any | the |
Returns: true if the path is a directory
mkdir
¶
mkdir - creates a new directory
Parameters
Name | Type | Description |
---|---|---|
dirname |
any | directory name to be created |
mode |
any | [0o755] directory mode |
recursive |
any | [true] if missing sub dirs should be created. |
Returns: ``
rmdir
¶
Deletes a directory if it exists.
Parameters
Name | Type | Description |
---|---|---|
dirname |
string | The path to the directory to delete. |
Returns: {void}
rm
¶
Deletes a file if it exists.
Parameters
Name | Type | Description |
---|---|---|
fname |
string | The path to the file to delete. |
Returns: {void}
readdir
¶
Reads the contents of a directory.
Parameters
Name | Type | Description |
---|---|---|
dirname |
string | The path to the directory to read. |
Returns: {string[]} An array of filenames in the directory.
read
¶
Reads the contents of a file.
Parameters
Name | Type | Description |
---|---|---|
fname |
string | The path to the file to read. |
Returns: {string} The contents of the file as a string.
abspath
¶
Resolves a relative path to an absolute path.
Parameters
Name | Type | Description |
---|---|---|
rel_path |
string | The relative path to resolve. |
Returns: {string} The absolute path.
rename
¶
Renames a file or directory.
Parameters
Name | Type | Description |
---|---|---|
old_path |
string | The path to the file or directory to rename. |
new_path |
string | The new path for the file or directory. |
Returns: {void}
move
¶
move ( old_path, new_path ) => void
Moves a file from old_path
to new_path
.
This function first tries using rename
function. If it cannot be used, then the file is copied and removed.
@see rename
Parameters
Name | Type | Description |
---|---|---|
old_path: |
any | |
new_path: |
any |
Returns: ``
write
¶
Writes data to a file.
Parameters
Name | Type | Description |
---|---|---|
full_path |
string | The path to the file to write to. |
data |
string | The data to write to the file. |
Returns: {void}
stat
¶
Gets information about a file or directory.
Parameters
Name | Type | Description |
---|---|---|
full_path |
string | The path to the file or directory to get information about. |
Returns: {fs.Stats} An object containing information about the file or directory.
basename
¶
Gets the base name of a file or directory path.
Parameters
Name | Type | Description |
---|---|---|
full_path |
string | The path to the file or directory. |
Returns: {string} The base name of the file or directory.
``¶
@ignore
creates a temp file in the full_path
given.
This function is sync.
Parameters
Name | Type | Description |
---|---|---|
path |
any | the |
name |
any | the |
mode |
any | file |
Returns: the full_path of the created file
symlink
¶
Creates a symbolic link.
Parameters
Name | Type | Description |
---|---|---|
src |
string | The path to the source file or directory. |
dest |
string | The path to the destination file or directory. |
Returns: {void}
createWriteStream
¶
Creates a write stream to the specified path with the given options.
Parameters
Name | Type | Description |
---|---|---|
path |
any | The path to the file. |
options |
any | The options for creating the write stream. |
Returns: The created write stream.
sanitize
¶
Takes a filename and returns a sanitized version of it. By default, it replaces all non-alphanumeric characters with underscores and converts to lowercase.
Parameters
Name | Type | Description |
---|---|---|
filename |
string | The filename to sanitize. |
Returns: {string} The sanitized filename.
fileSize
¶
Returns the size of a file in bytes.
Parameters
Name | Type | Description |
---|---|---|
path |
any | the |
Returns: the size of the file in bytes