Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Setting everything up
- local args = {...} -- Read arguments
- local target -- Create reference to targte file
- local contents -- Create array for new lines to be written
- local function rFile(file) -- Return an array with the contents of the file
- local f = fs.open(file,"r")
- local ln = ""
- local ret = {}
- repeat
- ln = f.readLine()
- ret[#ret+1] = ln
- until ln == nil
- f.close()
- return ret
- end
- -- Execute --
- contents = {"--[["} -- The contents of each file will be written into a comment
- target = fs.open(args[1],((fs.exists(args[1]) and "a")) or ("w")) -- Open target file in either write (not existing) or append (existing) mode
- for i=2,#args,1 do
- local file = rFile(args[i]) -- Read the file into an array
- contents[#contents+1] = "NEWFILE" --Create header for the file
- contents[#contents+1] = args[i] -- Write file name
- for j=1,#file,1 do -- Write file contents into array of added lines
- contents[#contents+1] = file[j]
- end
- contents[#contents+1] = "EOF" -- Create marker for eof
- print("Added "..args[i])
- end
- contents[#contents+1] = "--]]" -- Close comment in added lines
- for i=1,#contents,1 do -- Write actual data to the target file
- target.writeLine(contents[i])
- end
- target.close()
- print("Done")
Add Comment
Please, Sign In to add comment