147 posts
Location
My Computer
Posted 01 December 2013 - 07:52 AM
Hello! I was trying to make a program that backed up all your files into a folder named "backup" (Yes, I know what rom is, it was just for the challenge aspect.) Now, on my current code, it works, but it still gives me an error when first trying to make a backup even though the program itself worked. The error it gives me is:
backup:11: No such file.
Current code:
print("Backcup creator.")
if fs.isDir("backup") then
sleep(1)
print("Backup already made.")
else
sleep(1)
print("Creating backup...")
fs.makeDir("backup")
s = shell.programs()
for _, v in ipairs(s) do
fs.copy(v, "backup/"..v)
sleep(1)
print("Backup created.")
end
end
Any help?
Edit: New problem! It works fine, but I want it to copy all the files, even the user created ones. Any help on that front?
Edited on 01 December 2013 - 07:37 AM
7508 posts
Location
Australia
Posted 01 December 2013 - 08:30 AM
I could be wrong, but I believe that what is returned from
shell.programs also includes aliases, which aren't files, but are references to files. As such you should use
fs.list instead of
shell.programs
local s = fs.list("/rom/programs/")
758 posts
Location
Budapest, Hungary
Posted 01 December 2013 - 08:31 AM
EDIT: And I was right! I knew I was going to be ninja'd!
Thing is, the point of a backup program is backing up all files (not just the programs) on the computer (well, except for the existing backups). List all files on the computer and copy them into a new directory (eg. string.format("~backup-%i-%i", os.day(), os.time())). fs.list is your friend.
Edited on 01 December 2013 - 07:31 AM
147 posts
Location
My Computer
Posted 01 December 2013 - 08:31 AM
Dank you!
147 posts
Location
My Computer
Posted 01 December 2013 - 08:36 AM
Edit: New problem! It works fine, but I want it to copy all the files, even the user created ones. Any help on that front?
7508 posts
Location
Australia
Posted 01 December 2013 - 09:01 AM
don't get a list of rom, get a list of the root directory and ignore the rom and the backups directory.
1522 posts
Location
The Netherlands
Posted 01 December 2013 - 09:09 AM
don't get a list of rom, get a list of the root directory and ignore the rom and the backups directory.
To extend on this, this is some actual code:
for index, filename in pairs(fs.list("/")) do
if not fs.isReadOnly(filename) then
print( string.format("The file \"%s\" is created by an user!", filename))
end
end
Edited on 01 December 2013 - 08:09 AM
147 posts
Location
My Computer
Posted 01 December 2013 - 01:59 PM
Dank you very much!