4 posts
Posted 19 November 2012 - 08:53 AM
ok, i have 2 computers (me and my friends) and we log players info on them. BUT every now and then we want to merge them so were both updated. BUT weve already merged them once (meaning both files have the same names now.) After we merged them, we both kept adding diffrent names. BUT now were in need of another merge,BUT if i were to merge them again it will duplicate the names we merged before (because both files have the same names from our first merge). PLEASE HELP i only want it to merge the new names we added
1054 posts
Posted 19 November 2012 - 09:15 AM
This is about ComputerCraft computers, right?
4 posts
Posted 19 November 2012 - 09:41 AM
Yes
536 posts
Posted 19 November 2012 - 10:00 AM
Then this is in the wrong section!
however, you can do this like so:
local function checkFor(table, check)
for i=1,#table do
if table[i] == check then return true end
end
return false
end
local function adv_merge(dirs, output)
local lines = {}
for i=1,#dirs do
if fs.exists(dirs[i]) then
local file = fs.open(dirs[i])
local line = file.readLine()
while line ~= nil do
if not checkFor(lines, line) then
lines[#lines + 1] = line
end
line = file.readLine()
end
file.close()
end
end
if #lines > 0 then
if fs.exists(output) then fs.delete(output) end
local file = fs.open(output)
for i=1,#lines do
file.writeLine(lines[i])
end
file.close()
end
end
and calling
adv_merge({"file1.txt", "file2.txt"}, "output.txt")
(for example)
(sorry about only giving code and no explanation, but I just can't really be bothered, very sorry!)
4 posts
Posted 19 November 2012 - 10:17 AM
Ok ill give it a try
4 posts
Posted 19 November 2012 - 10:33 AM
ok i have what you put, and adv_merge({"file1", "file2"}, "output") at the bottom, when i launch the program nothing happend