The implementation tries to follow the CommonJSspecification where possible.
The directory functions below shouldn’t use the current working directory of the server like
./test.You will not be able to tell whether the environment the server is running in will permit directory listing,reading or writing of files.
You should either base your directories with
getTempPath(), or as a Foxx service use themodule.context.basePath.
checks if a file of any type or directory exists
Returns true if a file (of any type) or a directory exists at a givenpath. If the file is a broken symbolic link, returns false.
tests if path is a file
Returns true if the path points to a file.
tests if path is a directory
Returns true if the path points to a directory.
gets the size of a file
Returns the size of the file specified by path.
gets the last modification time of a file
Returns the last modification date of the specified file. The date isreturned as a Unix timestamp (number of seconds elapsed since January 1 1970).
If you want to combine two paths you can use fs.pathSeparator instead of
The function returns the combination of the path and filename, e.g.
fs.join('folder', 'file.ext') would return
returns the name for a (new) temporary file
Returns the name for a new temporary file in directory directory.If createFile is true, an empty file will be created so no otherprocess can create a file of the same name.
Note: The directory directory must exist.
returns the temporary directory
Returns the absolute path of the temporary directory
makes a given path absolute
sets file permissions of specified files (non windows only)
where is a string with a leading zero matching the
OCTAL-MODE as explainedin *nix
Returns true on success.
returns the directory listing
The functions returns the names of all the files in a directory, inlexically sorted order. Throws an exception if the directory cannot betraversed (or path is not a directory).
Note: this means that list(“x”) of a directory containing “a” and “b” wouldreturn [“a”, “b”], not [“x/a”, “x/b”].
returns the directory tree
The function returns an array that starts with the given path, and all ofthe paths relative to the given path, discovered by a depth first traversalof every directory in any visited directory, reporting but not traversingsymbolic links to directories. The first path is always
"", the pathrelative to itself.
creates a directory
Creates the directory specified by path.
creates a directory
Creates the directory hierarchy specified by path.
removes a file
Removes the file filename at the given path. Throws an exception if thepath corresponds to anything that is not a file or a symbolic link. If“path” refers to a symbolic link, removes the symbolic link.
removes an empty directory
Removes a directory if it is empty. Throws an exception if the path is notan empty directory.
removes a directory
Removes a directory with all subelements. Throws an exception if the pathis not a directory.
reads in a file
Reads in a file and returns the content as string. Please note that thefile content must be encoded in UTF-8.
reads in a file as base64
Reads in a file and returns the content as string. The file content isBase64 encoded.
reads in a file
Reads the contents of the file specified in
encoding is specified,the file contents will be returned as a string. Supported encodings are:
encoding is specified, the file contents will be returned in a Bufferobject.
Writes the content into a file. Content can be a string or a Bufferobject. If the file already exists, it is truncated.
This is an alias for
Writes the content into a file. Content can be a string or a Bufferobject. If the file already exists, the content is appended at theend.
copies a directory structure
Copies source to destination.Exceptions will be thrown on:
- Failure to copy the file
- specifying a directory for destination when source is a file
copies a file into a target file
Copies source to destination. If Destination is a directory, a fileof the same name will be created in that directory, else the copy will getthespecified filename.
creates a symbolic link from a target in the place of linkpath.
linkpath a symbolic link to
target will be created.
renames a file
Moves source to destination. Failure to move the file, orspecifying a directory for destination when source is a file will throw anexception. Likewise, specifying a directory as source and destination willfail.
unzips a file
fs.unzipFile(filename, outpath, skipPaths, overwrite, password)
Unzips the zip file specified by filename into the path specified byoutpath. Overwrites any existing target files if overwrite is setto true.
Returns true if the file was unzipped successfully.
zips a file
Stores the files specified by files in the zip file filename. Ifthe file filename already exists, an error is thrown. The list of inputfiles files must be given as a list of absolute filenames. If chdir isnot empty, the chdir prefix will be stripped from the filename in thezip file, so when it is unzipped filenames will be relative.Specifying a password is optional.
Returns true if the file was zipped successfully.