FileSystem
This module provides access to the file system. It allows you to read and write files, create directories and links etc.
This value represents the permission to perform file system operations.
Only code you trust should have access to this value.
Initialize the FileSystem
subsystem, which gains you the permission to perform
file system operations.
Errors
Represents an error that occured when working with the file system.
There are many different kinds of error depending on which operation you're performing and which operating system you're performing it on. To figure out which error it is, you'll need to use one of the helper functions below, or check the specific error code.
A string that identifies a specific kind of error. There can be several error codes for the same kind of error, depending on the operating system that is in use.
Returns a human readable description of the error.
If True
, the error occured because you don't have the correct access permission to perform
the operation.
If True
, a file exists when it was expected not to.
If True
, a file operation was attempted on a directory.
If True
, the application has too many open files.
If True
, the code was passed a Path which points to a file or directory
that doesn't exist.
If True
, a directory was expected but it found a file or some other entity.
If True
, the operation expected an empty directory, but the directory is not empty.
If True
, the operation was rejected because of missing privileges.
If True
, we seem to be stuck in a loop following link after link after...
If True
, the Path is too long.
If True
, the arguments passed to the function is invalid somehow.
If True
, the operation failed due to an IO error. This could be that the disk is
busy, or even corrupt.
Metadata
Represents extra information about an entity in the file system.
The type of an entity in the file system.
Return metadata for the entity represented by Path.
If resolveLink
is False
, you will receive metadata for the link itself, not the entity
pointed at by the link.
Represents the permission to access an entity for a specific operation.
For example: if you, or your group, doesn't have the Read
permission for a file,
you're not allowed to read from it.
Check if the user running this application has the given access permissions for the entity represented by Path.
Passing an empty Array
will check that the entity exists.
Change the access permissions for the entity's owner, group and everyone else.
The integer representation of a set of access permissions in a posix system.
accessPermissionsToInt [ Read, Write ] == 6
Change the user and group that owns a file.
You'll need the ID of the owner and group to perform this operation.
If resolveLink
is False
, you're changing the owner of the link itself,
not the entity it points to.
Change the registered time (down to the second) an entity was accessed and modified.
If resolveLink
is False
, you're changing the last access and modification time of the link itself,
not the entity it points to.
Move the entity represented by the last Path, to the location represented by the first Path. This can also be used to rename an entity.
If you have a Path that is relative to the current directory, or points at a link, you can use this find the true Path of the entity.
Files
Copy the file represented by the last Path, to the location represented by the first Path.
Add Bytes
to the end of a file.
Read the entire contents of a file.
Write the given Bytes
into a file. The file will be created if it doesn't exist,
and overwritten if it does.
Make sure the given file is of a specific length. If the file is smaller than the given length, zeroes is added to the file until it is the correct length. If the file is larger than the given length, the excess bytes are removed.
Remove the file or directory at the given path.
recursive
will delete everything inside a directory.ignoreErrors
will... ignore any errors related to a remove operation.
Directories
List the contents of a directory. The returned Paths are relative to the directory being listed.
Create a new directory at the given Path.
If recursive
is True
, then a directory will be created for every section of the
given Path.
Create a directory, prefixed by a given name, that ends up in a section of the file system reserved for temporary files. You're given the Path to this new directory.
Links
Creates a hard link from the last Path to the first.
A hard link is an alias for a specific location. The link has the same ownership and access permissions, and it's impossible to tell which is the "real" entity and which is the link.
Creates a soft link from the last Path to the first.
A soft link, also known as a symoblic link or symlink, is a special file that contains the path to some other location. Resolving a soft link will redirect to this other location.
Removes a link, hard or soft, from the file system. If the Path refers to a file, the file is removed.
Watch for changes
Represents a change within a watched directory.
Changed
means that the contents of a file has changed in some way.Moved
means that an entity has been added or removed. A rename is usually twoMoved
events.
On most operating systems, each event will be associated with a Path relative to the watched directory, but some operating systems will not provide that information.
This notifies your application every time there is a change within the directory represented by the given Path.
Same as watch, but this will also watch for changes in sub-directories.
Special paths
Find the Path that represents the home directory of the current user.
Returns the current working directory of the program.
This is the directory that all relative paths are relative to, and is usually the directory that the program was executed from.
Find a Path that represents a directory meant to hold temporary files.