Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Set up everything
- local args = {...}
- local data = {}
- local files = 0
- local cursor = 0
- --Open file and read contens into array
- local file = fs.open(args[1],"r")
- local ln = ""
- while true do
- ln = file.readLine()
- if ln then
- data[#data+1] = ln
- else
- break
- end
- end
- file.close()
- file = nil
- ln = nil
- --Get amount of files stored
- for i=1,#data,1 do
- if data[i] == "NEWFILE" then
- files = files+1
- end
- end
- print("Files found: "..files)
- --Dump function
- local function dmp(s,c)
- local newfile = fs.open(s,"w")
- for i=1,#c,1 do
- newfile.writeLine(c[i])
- end
- newfile.close()
- print("Created file \""..s.."\"")
- return
- end
- --Goto file function
- local function nextfile()
- repeat
- cursor = cursor +1
- until data[cursor] == "NEWFILE"
- end
- --Read specific file
- for i=1,files,1 do
- nextfile() --Goto next file
- local cfile = {}
- cursor = cursor +1
- local name = data[cursor]
- cursor = cursor +1
- repeat
- cfile[#cfile+1] = data[cursor]
- cursor = cursor +1
- until data[cursor] == "EOF"
- dmp(name,cfile)
- end
- --[[
- NEWFILE
- Hello
- print("Hello, world!")
- --Hello
- EOF
- --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement