Advertisement
minimite

list

Sep 14th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. local tArgs = { ... }
  2.  
  3. -- Get all the files in the directory
  4. local sDir = shell.dir()
  5. if tArgs[1] ~= nil then
  6.     sDir = shell.resolve( tArgs[1] )
  7. end
  8.  
  9. -- Sort into dirs/files, and calculate column count
  10. local tAll = fs.list( sDir )
  11. local tFiles = {}
  12. local tDirs = {}
  13. local tHidden = {}
  14. local tHiddenDir = {}
  15.  
  16. for n, sItem in pairs( tAll ) do
  17.     if string.sub( sItem, 1, 1 ) ~= "." then
  18.                         local sPath = fs.combine( sDir, sItem )
  19.         if fs.isDir( sPath ) then
  20.             table.insert( tDirs, sItem )
  21.         else
  22.             table.insert( tFiles, sItem )
  23.         end
  24. elseif string.sub( sItem, 1, 1) == "." then
  25. local sPath = fs.combine( sDir, sItem )
  26. if fs.isDir( sPath ) then
  27.                         table.insert( tHiddenDir, sItem)
  28. else
  29. table.insert( tHidden, sItem)
  30. end
  31.     end
  32. end
  33. table.sort( tDirs )
  34. table.sort( tFiles )
  35. table.sort( tHidden )
  36. table.sort( tHiddenDir )
  37.  
  38. if term.isColour() then
  39.     textutils.pagedTabulate( colors.green, tDirs, colors.lightGray, tFiles, colors.orange, tHidden, colors.red, tHiddenDir )
  40. else
  41.     textutils.pagedTabulate( tDirs, tFiles, tHidden, tHiddenDir )
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement