File
The File
API gives access to the local filesystem.
Most of the File
methods return Promises
that resolve with the data
requested, or throw on I/O failures.
The current working directory.
The user home directory.
The preferred path separator for the current platform. This is usually the
forward slash character /
, but is a backslash \
on Windows.
The system directory for temporary files.
File.basename()(string) => string
Returns the name of the file at the end of the given string path.
File.copy()(string, string) => Promise<void>
Copies a file from the path in the first parameter to the path in the second parameter. See copyTree for a similar method that can copy entire directories, recursively.
File.copyTree()(string, string) => Promise<void>
Copies the file or directory in the first parameter to the path in the second parameter. This method will copy directories and their contents recursively.
File.dirname()(string) => string
Returns the path to the directory that contains the file path given in the first parameter.
File.isDir()(string) => Promise<boolean>
Returns true
if the given path is a directory. Returns false if the path
doesn’t exist or isn’t accessible to the current process.
File.isFile()(string) => Promise<boolean>
Returns true
if the given path is a file. Returns false if the path
doesn’t exist or isn’t accessible to the current process.
File.list()(string) => Promise<string[]>
Returns a list of all the files in the given directory. See listTree for a similar method that also returns the contents of subdirectories.
File.listTree()(string) => Promise<string[]>
Returns a list of all the files in the given directory, recursively.
File.mkdirs()(string) => Promise<void>
Creates all the missing directories in the given path.
File.readArrayBuffer()(string) => Promise<ArrayBuffer>
Returns the contents of the given file as an ArrayBuffer
.
File.readImageBitmap()(string) => Promise<ImageBitmap>
Returns the contents of the given file as an ImageBitmap.
File.readImageData()(string) => Promise<ImageData>
Returns the contents of the given file as an ImageData.
File.readJSON()(string) => Promise<Json>
Returns the contents of the given file as a JSON
object.
File.readText()(string) => Promise<sTring>
Returns the contents of the given file as a string.
File.remove()(string) => Promise<void>
Removes the given file. See removeTree for a similar method that can remove a directory and all of its contents, recursively.
File.removeTree()(string) => Promise<void>
Removes the given file or directory, and all of its contents, recursively.
File.rename()(string, string) => Promise<void>
Renames the file at the path in the first parameter to the path in the second parameter.
File.size()(string) => Promise<number>
Returns the size, in bytes, of the file at the given path.
File.write()(string, string | ArrayBuffer | TypedArray) => Promise<void>
Writes the contents of the object in the second parameter to the file path in the first parameter.
Valid object types for the second parameter:
ArrayBuffer |
Writes all of the bytes in the buffer. |
TypedArray |
Writes all of the bytes in the array. |
string |
Writes the string encoded in UTF-8. |