This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
bloodless2010's profile picture

Automatic program editing?

Started by bloodless2010, 15 July 2012 - 08:23 PM
bloodless2010 #1
Posted 15 July 2012 - 10:23 PM
OK, So bassically, I'm making a program and I have a lot of PC's I want to install it on,
but the thing is, I don't want to type is all out over and over, so I thought why not an "install" disk?
where I'd put a drive next to the console, put the disk in, and it would overwrite the startup with new code for my program, how would I accomplish the editting of startup within a program? Many thanks!
MysticT #2
Posted 15 July 2012 - 10:30 PM
Take a look at the fs api, specifically fs.copy.
Then just put the program in the disk and make the startup copy it to the computer.

Note: when using fs.copy, if the destination file already exists it will throw an error. You have to check if the file exists, and delete it before copying.
kazagistar #3
Posted 16 July 2012 - 03:04 PM
I think the even easier solution is to just use shell.run("copy", "disk/file", "startup")
MysticT #4
Posted 16 July 2012 - 03:44 PM
Yes, but he said overwrite, and copy throws an error if the file exists.
Exerro #5
Posted 16 July 2012 - 04:48 PM
for the install try using this code as the startup code on the disk (its quite easy tbh)
Spoiler

if fs.exists("startup") then
fs.delete("startup")
fs.copy("programname", "startup")
else
fs.copy("programname", "startup")
end
the only problem with this is that i have found fs.delete sometimes says action not allowed or something
Dirkus7 #6
Posted 17 July 2012 - 12:02 AM
for the install try using this code as the startup code on the disk (its quite easy tbh)
Spoiler

if fs.exists("startup") then
fs.delete("startup")
fs.copy("programname", "startup")
else
fs.copy("programname", "startup")
end
the only problem with this is that i have found fs.delete sometimes says action not allowed or something
shorter:
Spoiler
if fs.exists("startup") then
fs.delete("startup")
end
fs.copy("disk/file", "startup")
Does the same, just shortened it up