Is it possible to loop trough EVERY file in DATA folder and subfolders?
5 replies, posted
Hi !
local files,directories = file.Find("*","DATA")
for _,f in ipairs(files) do
print(f)
end
for _,dir in ipairs(directories) do
local files = file.Find(dir .. "/*","DATA")
for _,f in ipairs(files) do
print(f)
end
end
Here is my loop by now, but i wonder if it's possible to enhance it so it prints ALL files in the DATA folder, atm it only print files and first folder files :/
Do you mean subfolders?
More or less, i'm interested in printing all the files in the DATA folder
Something like this might work, haven't tested and also not the best way of doing it as you may run into call stack size issues.
local function doFileAction(files)
for _,f in ipairs(files) do
print(f)
end
end
local function searchDir(directories)
for _,dir in ipairs(directories) do
local files, dirs2 = file.Find(dir .. "/*","DATA")
doFileAction(files)
searchDir(dirs2)
end
end
local files,directories = file.Find("*","DATA")
doFileAction(files)
searchDir(directories)
I will test that tomorrow, thanks a lot i was thinking about this kind of algo but yeah callstack can be a problem here...
function PrintTree(name,path,tab)
print(name)
tab=tab and tab.."\t" or ""
local files,dirs=file.Find(name.."*",path)
for _,dir in pairs(dirs)do
PrintTree(name..dir.."/",path,tab)
end
for _,f in pairs(files)do
print(tab..f)
end
end
call PrintTree("","DATA")
resault:
texture/
texture/subfolder/
file1.txt
file2.txt
ulx/
ulx/tempuserdata/
data.txt
acrashscreen-volume.dat
Sorry, you need to Log In to post a reply to this thread.