Get file attributes (file.attrs)
Declaration
attrs, err = file.attrs(path [, request])
Parameters
- path
String. - request
Table or String, optional.- If a table is provided, the function fills this table with results instead of creating a new one.
- If a string is provided, returns only the specified field.
- When not specified, returns a table with all fields.
- "dev": device where the inode resides
- "ino": inode number
- "mode": file type, one of "file", "directory", "link", "socket", "named pipe", "char device", "block device" or "other"
- "nlink": hard link count
- "uid": owner user id
- "gid": owner group id
- "rdev": device type for special files
- "access": last access time
- "modification": last modification time
- "change": last status change time
- "size": file size in bytes
- "permissions": file permissions
- "blksize": optimal I/O block size
- "blocks": number of 512-byte blocks allocated
Returns
- attrs
Table or nil. Attributes table on success; nil on failure. - err
String. Error message when operation fails.
Notes
Get attributes of a file. If the path is a symbolic link, returns attributes of the target file. Equivalent to lfs.attributes.
Available in versions after 2025-07-05.
Example
local info, err = file.attrs("/var/mobile/Media/1ferver/lua/scripts/")
if info then
sys.alert("File info: "..json.encode(info))
else
sys.alert("Get attributes failed: "..err)
end
Note: Uses sys.alert