-- List the contents of directory "dir" into a table. Accepts relative directory to list. --Returns the table, and the full path to the directory OR error & code. function fs.dir(dir) if dir == "." or nil then else if dir == "~" then dir = "/home/"..posix.getpasswd(posix.getenv("USER")).name end local olddir = fs.cwd -- Save current/Old Directory local i, j, k = fs.cd(dir) if j then return j, k else end local ttable = {} local i = 0 for file in posix.files() do if i > 0 then -- Skip First entry (".") local filestat = posix.stat(file) ttable[i] = {} if filestat.type == "directory" then ttable[i].dir = true else ttable[i].dir = false end ttable[i].name = file ttable[i].size = filestat.size ttable[i].perms = filestat.mode ttable[i].mtime = filestat.mtime ttable[i].uid = posix.getpasswd(filestat.uid) ttable[i].gid = posix.getgroup(filestat.gid) end i = i + 1 end if dir == "." or nil then else local i, j, k = fs.cd(olddir) if j then return j, k end end return ttable, dir end