I'm trying to concatenate every file in a folder in lua to compile a bunch of logs into one master log and send it off to someone. I'm using the ifs library to iterate through every file in a directory, then reading it all in and trying to append it to the master file.
for name in lfs.dir("logs") do
if(name ~= "." and name ~= "..") then
local path = "logs/"..name
print (path)
local file=io.open(path,"R")
print "2"
local content = io.read("*all")
print "3"
io.close(file)
local f=io.open("log.csv","A")
file:write(content)
io.close(f)
end
end
There are two issues. The ifs library returns "." and ".." before the other file names [is there a better way to ignore these than an if statement?] using the bit I found here: How to load all files from a directory?
The important issue is that my command prompt keeps crashing when I test the file. It prints the path (a good one), then it crashes before getting to the "2" and I'm not sure why. The file exists and I can manipulate it by adding lines to it in another function.
Any help would be greatly appreciated.