This class provides methods for synchronous operations on files and
directories. For asynchronous operations, see nusys.async.FileSystem.
Passing null as a path to any of the functions in this class will result
in unspecified behaviour.
Static variables
Static methods
staticaccess (path:FilePath, mode:FileAccessMode = FileAccessMode.Ok):Void
Tests specific user permissions for the file specified by path. If the
check fails, throws an exception. mode is one or more FileAccessMode
values:
FileAccessMode.Ok- file is visible to the calling process (it exists)FileAccessMode.Execute- file can be executed by the calling procesFileAccessMode.Write- file can be written to by the calling procesFileAccessMode.Read- file can be read from by the calling proces
Mode values can be combined with the bitwise or operator, e.g. calling
access with the mode:
FileAccessMode.Execute | FileAccessMode.Read
will check that the file is both readable and executable.
The result of this call should not be used in a condition before a call to
e.g. open, because this would introduce a race condition (the file could
be deleted after the access call, but before the open call). Instead,
the latter function should be called immediately and errors should be
handled with a try ... catch block.
staticappendFile (path:FilePath, data:Bytes, ?flags:FileOpenFlags, ?mode:FilePermissions):Void
Available on cross
Appends data at the end of the file located at path.
staticchmod (path:FilePath, mode:FilePermissions, followSymLinks:Bool = true):Void
Changes the permissions of the file specific by path to mode.
If path points to a symbolic link, this function will change the
permissions of the target file, not the symbolic link itself, unless
followSymLinks is set to false.
TODO: followSymLinks == false is not implemented and will throw.
staticchown (path:FilePath, uid:Int, gid:Int, followSymLinks:Bool = true):Void
Changes the owner and group of the file specific by path to uid and
gid, respectively.
If path points to a symbolic link, this function will change the
permissions of the target file, not the symbolic link itself, unless
followSymLinks is set to false.
TODO: followSymLinks == false is not implemented and will throw.
staticcopyFile (src:FilePath, dest:FilePath):Void
Copies the file at src to dest. If dest exists, it is overwritten.
staticcreateReadStream (path:FilePath, ?options:FileReadStreamCreationOptions):FileReadStream
Creates a read stream (an instance of IReadable) for the given path.
options can be used to specify how the file is opened, as well as which
part of the file will be read by the stream.
options.flags- seeopen.options.mode- seeopen.options.autoClose- whether the file should be closed automatically once the stream is fully consumed.options.start- starting position in bytes (inclusive).options.end- end position in bytes (non-inclusive).
staticexists (path:String):Bool
Returns true if the file or directory specified by path exists.
The result of this call should not be used in a condition before a call to
e.g. open, because this would introduce a race condition (the file could
be deleted after the exists call, but before the open call). Instead,
the latter function should be called immediately and errors should be
handled with a try ... catch block.
staticmkdir (path:FilePath, recursive:Bool = false, ?mode:FilePermissions):Void
Creates a directory at the path path, with file mode mode.
If recursive is false (default), this function can only create one
directory at a time, the last component of path. If recursive is true,
intermediate directories will be created as needed.
staticmkdtemp (prefix:FilePath):FilePath
Creates a unique temporary directory. prefix should be a path template
ending in six X characters, which will be replaced with random characters.
Returns the path to the created directory.
The generated directory needs to be manually deleted by the process.
staticopen (path:FilePath, ?flags:FileOpenFlags, ?mode:FilePermissions, binary:Bool = true):File
Opens the file located at path.
staticreadFile (path:FilePath, ?flags:FileOpenFlags):Bytes
Reads all the bytes of the file located at path.
staticreaddir (path:FilePath):Array<FilePath>
Reads the contents of a directory specified by path. Returns an array of
FilePaths relative to the specified directory (i.e. the paths are not
absolute). The array will not include . or ...
staticreaddirTypes (path:FilePath):Array<DirectoryEntry>
Same as readdir, but returns an array of DirectoryEntry values instead.
staticreadlink (path:FilePath):FilePath
Returns the contents (target path) of the symbolic link located at path.
staticrealpath (path:FilePath):FilePath
Returns the canonical path name of path (which may be a relative path)
by resolving ., .., and symbolic links.
staticrename (oldPath:FilePath, newPath:FilePath):Void
Renames the file or directory located at oldPath to newPath. If a file
already exists at newPath, it is overwritten. If a directory already
exists at newPath, an exception is thrown.
staticrmdir (path:FilePath):Void
Deletes the directory located at path. If the directory is not empty or
cannot be deleted, an error is thrown.
staticstat (path:FilePath, followSymLinks:Bool = true):FileStat
Available on cross
Returns information about the file located at path.
If path points to a symbolic link, this function will return information
about the target file, not the symbolic link itself, unless followSymLinks
is set to false.
staticstat (path:FilePath, followSymLinks:Bool = true):Stat
Available on eval
Returns information about the file located at path.
If path points to a symbolic link, this function will return information
about the target file, not the symbolic link itself, unless followSymLinks
is set to false.
staticsymlink (target:FilePath, path:FilePath, type:SymlinkType = SymlinkType.SymlinkDir):Void
Creates a symbolic link at path, pointing to target.
The type argument is ignored on all platforms except Windows.
statictruncate (path:FilePath, len:Int = 0):Void
Truncates the file located at path to exactly len bytes. If the file was
larger than len bytes, the extra data is lost. If the file was smaller
than len bytes, the file is extended with null bytes.
staticutimes (path:FilePath, atime:Date, mtime:Date):Void
Modifies the system timestamps of the file located at path.
staticwatch (path:FilePath, recursive:Bool = false):FileWatcher
Creates a file watcher for path.
Parameters:
recursive | If |
|---|
staticwriteFile (path:FilePath, data:Bytes, ?flags:FileOpenFlags, ?mode:FilePermissions):Void
Writes data to the file located at path.