Gets information about the file or directory specified by path. It returns a table of attributes containing the date and time the file was created and modified, the size of the file in bytes, and whether or not the path is a directory. If the file does not exist, you will receive a
No such file error.
||N/A||The date and time the file or directory was created, as a Unix time in milliseconds.|
||N/A||The date and time the file or directory was last modified, as a Unix time in milliseconds.|
||fs.isDir||Whether or not this path is a directory.|
||fs.getSize||The size of this file, in bytes. Returns |
|Prints information about path passed in as an argument. The program can be used from the CraftOS shell with the command
-- Get the path from the command local path = ... if not path then error("Usage: attributes [path]") end -- Get the file attributes local attr = fs.attributes(path) if attr.isDir then print(path, "is a directory.") else print(path, "is a file.") print("File size:", attr.size, "bytes") end -- Format the times in a human-friendly way. See: os.date() -- Note: os.date() expects seconds, but we have milliseconds, so we must divide -- the times by 1000 to get them in seconds. print("Created:", os.date("%c", attr.created / 1000)) print("Modified:", os.date("%c", attr.modification / 1000))