Listing All Files and Directories Seperately
EtzGamer 28 Jun 2016
I am trying to list all files and directories on the root directory with fs.list("/") and then seperate them to individual tables.
However, it does seem to be listing the files and directories correctly.
Code:
However, it does seem to be listing the files and directories correctly.
Code:
Spoiler
The_Cat 28 Jun 2016
You made the smallest error
-- Test file lister local tFsList = fs.list("/") local tDirList = {} local tFileList = {} --#local i = 1 for i, file in ipairs(tFsList) do --for i=1, #tFsList, 1 do print(file) if fs.isDir(file) then table.insert(tDirList, file) else table.insert(tFileList, file) end end print("Files:") --#local i = 1 for i=1, #tFileList do print(tFileList[i]) end print("Directories:") --#local i = 1 You also don't need to make a variable here, it will get created in the for loop for i=1, #tDirList do --#print(tFileList[i]) <-- Was this print(tDirList[i]) --# <-- Now this end
EtzGamer 29 Jun 2016
The_Cat, on 28 June 2016 - 08:50 AM, said:
You made the smallest error
-- Test file lister local tFsList = fs.list("/") local tDirList = {} local tFileList = {} --#local i = 1 for i, file in ipairs(tFsList) do --for i=1, #tFsList, 1 do print(file) if fs.isDir(file) then table.insert(tDirList, file) else table.insert(tFileList, file) end end print("Files:") --#local i = 1 for i=1, #tFileList do print(tFileList[i]) end print("Directories:") --#local i = 1 You also don't need to make a variable here, it will get created in the for loop for i=1, #tDirList do --#print(tFileList[i]) <-- Was this print(tDirList[i]) --# <-- Now this end
Eheh.
I couldn't believe I overlooked that minor slip-up on the code
I really do appreciate your help