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 Filesystem component with which this API works.
filesystem.isAutorunEnabled(): booleantrue, newly mounted file systems will be checked for a file named autorun[.lua] in their root directory. If such a file exists, it is executed.filesystem.setAutorunEnabled(value: boolean)filesystem.canonical(path: string): string. or ... For example, the paths /tmp/../bin/ls.lua and /bin/./ls.lua are equivalent, and their canonical form is /bin/ls.lua.../bin/ls.lua becomes bin/ls.lua. It stays a relative path, however - mind the lack of a leading slash.filesystem.segments(path: string): tablefilesystem.segments("foo/bar") → {"foo","bar"}filesystem.segments("foo/bar/../baz") → {"foo","baz"}filesystem.concat(pathA: string, pathB: string[, ...]): stringfs.concat("a", "..") results in an empty string.filesystem.path(path: string): stringfilesystem.name(path: string): stringfilesystem.proxy(filter: string): table or nil, stringcomponent.proxy, except that the specified string may also be a file system component's label. We check for the label first, if no file system has the specified label we fall back to component.proxy.
Returns the proxy of the specified file system, or nil and an error message if no file system matching the specified filter was found.filesystem.mount(fs: table or string, path: string): boolean or nil, stringnil and an error message otherwise.filesystem.mounts(): function -> table, stringfilesystem.umount(fsOrPath: table or string): booleanfilesystem.isLink(path: string): boolean[, string]filesystem.link(target: string, linkpath: string): boolean or nil, stringfilesystem.get(path: string): table, string or nil, stringnil and an error message.filesystem.exists(path: string): booleanfilesystem.size(path: string): numberfilesystem.isDirectory(path: string): booleanfile.exists(path) is false.filesystem.lastModified(path: string): numberfilesystem.list(path: string): function -> string or nil, stringnil and an error messages if the path is invalid or some other error occurred.fs.isDirectory.filesystem.makeDirectory(path: string): boolean or nil, stringtrue on success, nil and an error message otherwise.filesystem.remove(path: string): boolean or nil, stringtrue on success, nil and an error message otherwise.filesystem.rename(oldPath: string, newPath: string): boolean or nil, stringtrue on success, nil and an error message otherwise.filesystem.copy(fromPath: string, toPath: string): boolean or nil, stringfilesystem.open(path: string[, mode: string]): table or nil, stringr, rb, w, wb, a and ab.nil and an error message otherwise.close on the file stream when done with the file.io.open instead of this function, to get a buffered wrapper for the file stream.
When opening files directly via the file system API you will get a file stream, a table with four functions. These functions are thin wrappers to the file system proxy's callbacks, which also means that read/write operations are not buffered, and can therefore be slow when reading few bytes often. You'll usually want to use io.open instead.
file:close()file:read(n: number): string or nil, stringnil when the end of the stream was reached. Returns nil and an error message if some error occurred.file:seek(whence: string[, offset: number]): number or nil, stringcur for the current position, set for the beginning of the stream and end for the end of the stream. The second parameter is the offset by which to modify the position. Returns the new position or nil and an error message if some error occurred.f:seek("set") will reset the position to the start of the file, f:seek("cur") will return the current position in the file.file:write(str: value): boolean or nil, stringtrue on success, nil and an error message otherwise.