Well, for finding if it exists already, you can use:
if fs.exists("fileX") then
fs.delete("fileX")
end
But, for figuring out the version numbers, that depends on what your first line is. Personally I would just make the first line of any program the version number, with a comment tag.
Sample:
-- 3.14
So, figuring that out would be something akin to this:
Spoiler
if fs.exists("fileX") then
-- Following Section gathers the Version lines, supposing you mak it the first line of the program. --
fOld = fs.open("fileX", "r") -- Read HD File.
fNew = fs.open("disk/fileX", "r" -- Read DISK File
sOldVer = fOld.readLine() -- Get first line of HD file
sNewVer = fNew.readLine() -- Get first line of DISK file
fOld.close() -- Saves any file changes to the HD (since we use "r" instead of "w", no changes, so it just releases the file)
fNew.close() -- Saves any file changes to the DISK (since we use "r" instead of "w", no changes, so it just releases the file)
-- Following Section will find the numbers, and compare them
sOldVer = tonumber(string.sub(sOldVer, 4, #sOldVer)) -- Using the comment line I used as an example, this would grab the number 3.14, since 3 is the third char on the line, and the string is only 8 chars long.
sNewVer = tonumber(string.sub(sNewVer, 4, #sNewVer)) -- See last line
if sNewVer > sOldVer then -- Comparison and replacement.
fs.delete("fileX")
fs.copy("disk/fileX", "fileX")
end
end
But this is rough, and probably won't work properly. But even if it doesn't, you should be able to figure out how to do it from this.