ArangoDB v2.8 reached End of Life (EOL) and is no longer supported.
This documentation is outdated. Please see the most recent version here: Try latest
Module “fs”
The implementation tries to follow the CommonJS specification where possible. Filesystem/A/0.
Single File Directory Manipulation
exists
fs.exists(path)
Returns true if a file (of any type) or a directory exists at a given
path. If the file is a broken symbolic link, returns false.
isFile
fs.isFile(path)
Returns true if the path points to a file.
isDirectory
fs.isDirectory(path)
Returns true if the path points to a directory.
size
fs.size(path)
Returns the size of the file specified by path.
mtime
fs.mtime(filename)
Returns the last modification date of the specified file. The date is
returned as a Unix timestamp (number of seconds elapsed since January 1 1970).
pathSeparator
fs.pathSeparator
If you want to combine two paths you can use fs.pathSeparator instead of /
or \\
.
join
fs.join(path, filename)
The function returns the combination of the path and filename, e.g.
fs.join('folder', 'file.ext')
would return folder/file.ext
.
getTempFile
fs.getTempFile(directory, createFile)
Returns the name for a new temporary file in directory directory.
If createFile is true, an empty file will be created so no other
process can create a file of the same name.
Note: The directory directory must exist.
getTempPath
fs.getTempPath()
Returns the absolute path of the temporary directory
makeAbsolute
fs.makeAbsolute(path)
Returns the given string if it is an absolute path, otherwise an
absolute path to the same location is returned.
chmod
fs.exists(path)
Returns true on success.
list
fs.list(path)
The functions returns the names of all the files in a directory, in
lexically sorted order. Throws an exception if the directory cannot be
traversed (or path is not a directory).
Note: this means that list(“x”) of a directory containing “a” and “b” would
return [“a”, “b”], not [“x/a”, “x/b”].
listTree
fs.listTree(path)
The function returns an array that starts with the given path, and all of
the paths relative to the given path, discovered by a depth first traversal
of every directory in any visited directory, reporting but not traversing
symbolic links to directories. The first path is always ”“, the path
relative to itself.
makeDirectory
fs.makeDirectory(path)
Creates the directory specified by path.
makeDirectoryRecursive
fs.makeDirectoryRecursive(path)
Creates the directory hierarchy specified by path.
remove
fs.remove(filename)
Removes the file filename at the given path. Throws an exception if the
path corresponds to anything that is not a file or a symbolic link. If
“path” refers to a symbolic link, removes the symbolic link.
removeDirectory
fs.removeDirectory(path)
Removes a directory if it is empty. Throws an exception if the path is not
an empty directory.
removeDirectoryRecursive
fs.removeDirectoryRecursive(path)
Removes a directory with all subelements. Throws an exception if the path
is not a directory.
File IO
read
fs.read(filename)
Reads in a file and returns the content as string. Please note that the
file content must be encoded in UTF-8.
read64
fs.read64(filename)
Reads in a file and returns the content as string. The file content is
Base64 encoded.
readBuffer
fs.readBuffer(filename)
Reads in a file and returns its content in a Buffer object.
readFileSync
fs.readFileSync(filename, encoding)
Reads the contents of the file specified in filename
. If encoding
is specified,
the file contents will be returned as a string. Supported encodings are:
utf8
orutf-8
ascii
base64
ucs2
orucs-2
utf16le
orutf16be
hex
If no encoding
is specified, the file contents will be returned in a Buffer
object.
save
fs.write(filename, content)
Writes the content into a file. Content can be a string or a Buffer object.
writeFileSync
fs.writeFileSync(filename, content)
This is an alias for fs.write(filename, content)
.
Recursive Manipulation
copyRecursive
fs.copyRecursive(source, destination)
Copies source to destination.
Exceptions will be thrown on:
- Failure to copy the file
- specifying a directory for destination when source is a file
- specifying a directory as source and destination
CopyFile
fs.copyFile(source, destination)
Copies source to destination. If Destination is a directory, a file
of the same name will be created in that directory, else the copy will get the
specified filename.
move
fs.move(source, destination)
Moves source to destination. Failure to move the file, or
specifying a directory for destination when source is a file will throw an
exception. Likewise, specifying a directory as source and destination will
fail.
ZIP
unzipFile
fs.unzipFile(filename, outpath, skipPaths, overwrite, password)
Unzips the zip file specified by filename into the path specified by
outpath. Overwrites any existing target files if overwrite is set
to true.
Returns true if the file was unzipped successfully.
zipFile
fs.zipFile(filename, chdir, files, password)
Stores the files specified by files in the zip file filename. If
the file filename already exists, an error is thrown. The list of input
files files must be given as a list of absolute filenames. If chdir is
not empty, the chdir prefix will be stripped from the filename in the
zip file, so when it is unzipped filenames will be relative.
Specifying a password is optional.
Returns true if the file was zipped successfully.