Advertisement
funnybunnyofdoom

fileSys

Nov 28th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.71 KB | None | 0 0
  1. --This is the file system for BunnyOS
  2. --Author: FunnyBunnyofDOOM
  3.  
  4. --Objective: Display files and folders
  5. -- and allow file management
  6.  
  7. function buildDir(dir)
  8.   if dir == nil then dir = '/' end --default statement
  9.   local fileArray = fs.list(dir) --get the files in directory
  10.   local files = {}
  11.   local folders = {}
  12.   local folderIndex = 1
  13.   local fileIndex = 1
  14.   for i=1,#fileArray do
  15.     if fs.isDir(fileArray[i]) then
  16.       folders[folderIndex] = fileArray[i]
  17.       folderIndex = folderIndex + 1
  18.     else
  19.       files[fileIndex] = fileArray[i]
  20.       fileIndex = fileIndex + 1
  21.     end
  22.   end
  23.  
  24.   return fileArray,files,folders
  25. end
  26.  
  27. --Test code:
  28. x,y,z = buildDir()
  29. print(x[2].." "..y[1].." "..z[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement