此运行库提供了与文件系统组件交互的通用方法。每个文件系统组件都是一个“文件夹”,这些文件夹可以被“挂载”到全局文件目录树的某个位置,这样用户可以顺利地同时访问多个文件系统组件。
请不要将此API与文件系统组件API的作用混淆。
filesystem.isAutorunEnabled(): booleantrue,则新挂载文件系统时电脑会在其根目录中查找是否存在名为autorun[.lua]的文件。若存在,则会执行此文件。filesystem.setAutorunEnabled(value: boolean)filesystem.canonical(path: string): string. 或 ..的形式。/tmp/../bin/ls.lua和/bin/./ls.lua 两个路径是等价的,它们的规范路径为/bin/ls.lua。../bin/ls.lua会变成bin/ls.lua。然而,它仍然是一个相对路径——注意开头没有斜杠。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", "..")的结果将是空字符串。filesystem.path(path: string): stringfilesystem.name(path: string): stringfilesystem.proxy(filter: string): table or nil, stringcomponent.proxy,区别为给定字符串也可以为文件系统组件的标签。系统将会首先检查是否存在对应标签,若不存在拥有对应标签的文件系统,系统将回退执行 component.proxy。
返回值为指定文件系统的代理对象,若未找到匹配给定过滤器的文件系统则会返回 nil 和一条报错信息。filesystem.mount(fs: table or string, path: string): boolean or nil, stringtrue,若挂载失败返回nil和一条报错信息。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与一条报错信息。filesystem.exists(path: string): booleanfilesystem.size(path: string): numberfilesystem.isDirectory(path: string): booleanfalse,不论是因为路径指向了文件还是因为file.exists(path)的返回值为false,即路径不存在。filesystem.lastModified(path: string): numberfilesystem.list(path: string): function -> string or nil, stringnil和一条报错信息。fs.isDirectory的情况下识别其是否为目录。filesystem.makeDirectory(path: string): boolean or nil, stringtrue,失败时返回nil和一条报错信息。filesystem.remove(path: string): boolean or nil, stringtrue,失败时返回nil和一条报错信息。filesystem.rename(oldPath: string, newPath: string): boolean or nil, stringtrue,失败时返回nil和一条报错信息。filesystem.copy(fromPath: string, toPath: string): boolean or nil, stringfilesystem.open(path: string[, mode: string]): table or nil, stringr。打开模式可以为:r、rb、w、wb、a与ab。nil和一条报错信息。close手动关闭文件流更好。io.open而不是此函数,因为可以获得文件流的有缓冲包装版本。io.open代替。file:close()file:read(n: number): string or nil, stringnil。当发生错误时返回nil和一条报错信息。file:seek(whence: string[, offset: number]): number or nil, stringcur(当前位置)、set(文件流开头)或end(文件流结尾)。第二个参数为更改位置的偏移量。成功时返回新位置,失败时返回 nil和一条报错信息。f:seek("set")会将位置重置为文件开头,f:seek("cur")将会返回当前在文件中的位置。file:write(str: value): boolean or nil, stringtrue,失败时返回nil和一条报错信息。