Jump to content




Creating backups


  • You cannot reply to this topic
7 replies to this topic

#1 mrpoopy345

  • Members
  • 148 posts
  • LocationMy 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 by mrpoopy345, 01 December 2013 - 08:37 AM.


#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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/")


#3 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, 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 by LBPHacker, 01 December 2013 - 08:31 AM.


#4 mrpoopy345

  • Members
  • 148 posts
  • LocationMy Computer

Posted 01 December 2013 - 08:31 AM

Dank you!

#5 mrpoopy345

  • Members
  • 148 posts
  • LocationMy 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?

#6 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

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.

#7 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 01 December 2013 - 09:09 AM

View Posttheoriginalbit, on 01 December 2013 - 09:01 AM, said:

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 by Engineer, 01 December 2013 - 09:09 AM.


#8 mrpoopy345

  • Members
  • 148 posts
  • LocationMy Computer

Posted 01 December 2013 - 01:59 PM

Dank you very much!





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users