How can I get a Table with all files on a Computer? fs.list shows only one directory. The files should have the corect path, so that I can work with them.
List all Files of a Computer
Started by Wilma456, Aug 28 2016 10:47 AM
2 replies to this topic
#1
Posted 28 August 2016 - 10:47 AM
#2
Posted 28 August 2016 - 12:21 PM
Use fs.list recursively.
local tFiles = {}
local scanDir
function scanDir( sDir )
local t = fs.list( sDir )
for k, v in pairs( t ) do
local sFullName = fs.combine( sDir, v )
if fs.isDir( sFullName ) then
scanDir( sFullName )
else
tFiles[ #tFiles + 1 ] = sFullName
end
end
end
#3
Posted 28 August 2016 - 01:01 PM
KingofGamesYami, on 28 August 2016 - 12:21 PM, said:
Use fs.list recursively.
Use a stack:
local files = { }
local stack = { "" }
while #stack > 0 do
local dir = stack[1]
table.remove(stack, 1)
local t = fs.list(dir)
for i = 1, #t do
local path = dir.."/"..t[i]
if fs.isDir(path) then
table.insert(stack, 1, path)
else
files[#files + 1] = path
end
end
end
Note: this will also include all files in /rom.
If you want to ignore the /rom directory, use this:
local files = { }
local stack = { "" }
while #stack > 0 do
local dir = stack[1]
table.remove(stack, 1)
if dir ~= "/rom" then
local t = fs.list(dir)
for i = 1, #t do
local path = dir.."/"..t[i]
if fs.isDir(path) then
table.insert(stack, 1, path)
else
files[#files + 1] = path
end
end
end
end
Edited by CrazedProgrammer, 28 August 2016 - 01:04 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











