Jump to content




Listing All Files and Directories Seperately

computer api

2 replies to this topic

#1 EtzGamer

  • Members
  • 11 posts

Posted 28 June 2016 - 06:54 AM

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:
Spoiler


#2 The_Cat

  • Members
  • 119 posts

Posted 28 June 2016 - 08:50 AM

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


#3 EtzGamer

  • Members
  • 11 posts

Posted 29 June 2016 - 11:07 AM

View PostThe_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 :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users