Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
api:filesystem [2014/07/07 10:48]
vexatos
api:filesystem [2020/07/25 22:58] (current)
saphire Added link to Filesystem component
Line 1: Line 1:
 Filesystem API Filesystem API
 ============ ============
-This library allows a general way of interacting with file system components. While each component is it's own "​folder",​ these folders can be "​mounted"​ somewhere into a global directory tree. This allows seamlessly interacting on multiple file system components.+This library allows a general way of interacting with file system components. While each component is it's own "​folder",​ these folders can be "​mounted"​ somewhere into a global directory tree. This allows seamlessly interacting on multiple file system components. Not to be confused with the [[component:​filesystem|Filesystem component]] with which this API works.
  
 - `filesystem.isAutorunEnabled():​ boolean`  ​ - `filesystem.isAutorunEnabled():​ boolean`  ​
Line 10: Line 10:
   Returns the canonical form of the specified path, i.e. a path containing no "​indirections"​ such as `.` or `..`. For example, the paths `/​tmp/​../​bin/​ls.lua` and `/​bin/​./​ls.lua` are equivalent, and their canonical form is `/​bin/​ls.lua`.  ​   Returns the canonical form of the specified path, i.e. a path containing no "​indirections"​ such as `.` or `..`. For example, the paths `/​tmp/​../​bin/​ls.lua` and `/​bin/​./​ls.lua` are equivalent, and their canonical form is `/​bin/​ls.lua`.  ​
   Note that this function truncates relative paths to their topmost "​known"​ directory. For example, `../​bin/​ls.lua` becomes `bin/​ls.lua`. It stays a relative path, however - mind the lack of a leading slash.   Note that this function truncates relative paths to their topmost "​known"​ directory. For example, `../​bin/​ls.lua` becomes `bin/​ls.lua`. It stays a relative path, however - mind the lack of a leading slash.
 +- `filesystem.segments(path:​ string): table`  ​
 +  Returns a table containing one entry for each //​canonical//​ segment of the given path.
 +  Examples:  ​
 +  * `filesystem.segments("​foo/​bar"​)` -> `{"​foo","​bar"​}`
 +  * `filesystem.segments("​foo/​bar/​../​baz"​)` -> `{"​foo","​baz"​}`
 +
 - `filesystem.concat(pathA:​ string, pathB: string[, ...]): string`  ​ - `filesystem.concat(pathA:​ string, pathB: string[, ...]): string`  ​
   Concatenates two or more paths. Note that all paths other than the first are treated as relative paths, even if they begin with a slash. The canonical form of the resulting concatenated path is returned, so `fs.concat("​a",​ "​.."​)` results in an empty string.   Concatenates two or more paths. Note that all paths other than the first are treated as relative paths, even if they begin with a slash. The canonical form of the resulting concatenated path is returned, so `fs.concat("​a",​ "​.."​)` results in an empty string.
Line 25: Line 31:
 - `filesystem.umount(fsOrPath:​ table or string): boolean`  ​ - `filesystem.umount(fsOrPath:​ table or string): boolean`  ​
   Unmounts a file system. The parameter can either be a file system component'​s proxy or (abbreviated) address, in which case all mount points of this file system will be removed, or a path into the global directory structure, in which case the file system mount containing that directory will be unmounted.   Unmounts a file system. The parameter can either be a file system component'​s proxy or (abbreviated) address, in which case all mount points of this file system will be removed, or a path into the global directory structure, in which case the file system mount containing that directory will be unmounted.
 +- `filesystem.isLink(path:​ string): boolean[, string]`  ​
 +  Checks if the object at the specified path is a symlink, if so returns the path to where it links (as of 1.3.3).
 +- `filesystem.link(target:​ string, linkpath: string): boolean or nil, string`  ​
 +  Creates a symbolic link to the specified target path at the specified path. This is a '​soft'​ link, i.e. it the target file does not actually have to exist at the time of creation, and the link will not be deleted if the target file is deleted. Symbolic links do not persist across reboots.
 - `filesystem.get(path:​ string): table, string or nil, string`  ​ - `filesystem.get(path:​ string): table, string or nil, string`  ​
   Gets the file system component'​s proxy that contains the specified path. Returns the proxy and mount path, or `nil` and an error message.   Gets the file system component'​s proxy that contains the specified path. Returns the proxy and mount path, or `nil` and an error message.
Line 34: Line 44:
   Gets whether the path points to a directory. Returns false if not, either because the path points to a file, or `file.exists(path)` is false.   Gets whether the path points to a directory. Returns false if not, either because the path points to a file, or `file.exists(path)` is false.
 - `filesystem.lastModified(path:​ string): number`  ​ - `filesystem.lastModified(path:​ string): number`  ​
-  Returns the *real world* ​unicode ​timestamp of the last time the file at the specified path was modified. For directories this is usually the time of their creation.+  Returns the *real world* ​unix timestamp of the last time the file at the specified path was modified. For directories this is usually the time of their creation.
 - `filesystem.list(path:​ string): function -> string or nil, string`  ​ - `filesystem.list(path:​ string): function -> string or nil, string`  ​
   Returns an iterator over all elements in the directory at the specified path. Returns `nil` and an error messages if the path is invalid or some other error occurred.  ​   Returns an iterator over all elements in the directory at the specified path. Returns `nil` and an error messages if the path is invalid or some other error occurred.  ​
   Note that directories usually are postfixed with a slash, to allow identifying them without an additional call to `fs.isDirectory`.   Note that directories usually are postfixed with a slash, to allow identifying them without an additional call to `fs.isDirectory`.
 - `filesystem.makeDirectory(path:​ string): boolean or nil, string`  ​ - `filesystem.makeDirectory(path:​ string): boolean or nil, string`  ​
-  Creates a new directory at the specified path. Creates any parent directories that do not extist ​yet, if necessary. Returns `true` on success, `nil` and an error message otherwise.+  Creates a new directory at the specified path. Creates any parent directories that do not exist yet, if necessary. Returns `true` on success, `nil` and an error message otherwise.
 - `filesystem.remove(path:​ string): boolean or nil, string`  ​ - `filesystem.remove(path:​ string): boolean or nil, string`  ​
   Deletes a file or folder. If the path specifies a folder, deletes all files and subdirectories in the folder, recursively. Return `true` on success, `nil` and an error message otherwise.   Deletes a file or folder. If the path specifies a folder, deletes all files and subdirectories in the folder, recursively. Return `true` on success, `nil` and an error message otherwise.