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

Program Copier

Started by Nick0157, 24 November 2013 - 09:37 AM
Nick0157 #1
Posted 24 November 2013 - 10:37 AM
Hi!
This is a small program I've spent some time on today, that allows you to easily copy one program, from a computer to a floppy disk, and vice versa.

Tutorial
SpoilerFor this example, I will copy a startup program from one computer onto another.



We now want to copy "disk/copy" to "startup" on the next computer. To do this, take your disk, and place it
in another disk drive, next to your other computer.


Code
Spoiler

--visuals
term.clear()
term.setCursorPos(1,1)
print("Nick's Program Changer")

term.setCursorPos(1,3)
print("Enter target program:")

--main code
sleep(1)
input = read()

term.setCursorPos(1,6)
print("Enter replacement program:")
sleep(1)
input2 = read()


exist = fs.exists(input)


if exist == true then
  fs.delete(input)
  fs.copy(input2,input)
  sleep(3)
  print("Process Completed")
else
  fs.copy(input2,input)
  sleep(3)
  print("Process Completed")
end 

--reset visuals
sleep(1)
term.clear()
term.setCursorPos(1,1)

Pastebin Code - rHYQQxRu

I know its not the best code. Only the second successful one I've wrote. I find it useful, and I hope you do too!

Nick
LBPHacker #2
Posted 24 November 2013 - 11:10 AM
Functionally the same program:
-- why messing with the cursor here?
print("Spinoff of 'Nick's Program Changer'\n\nEnter source path:")
-- no sleeping here, that annoys the hell out of everybody
local sourcePath = read()
print("Enter destination path:")
-- no sleeping here, that annoys the hell out of everybody
local destPath = read()
-- no sleeping here, that annoys the hell out of everybody
fs.copy(sourcePath, destPath)
-- no sleeping here, that annoys the hell out of everybody
-- again, why messing with the cursor? nothing extraordinary happened, after all
With the difference that it lacks sleeps and messing with the cursor.
Edited on 24 November 2013 - 10:10 AM
BillyTheCodingKid #3
Posted 01 December 2013 - 06:25 PM
couldn't you just use the mv command?
secret1timb7 #4
Posted 01 December 2013 - 08:27 PM
Still dont get how this is newer then my post and has more views then my ATARI based game, You can just do "copy PROGRAM disk/NEWPROGRAMNAME", This is useless and child's code
LBPHacker #5
Posted 02 December 2013 - 12:18 AM
-snip-
Man, that was harsh.
[namedspoiler=OP, don't read this]OP: Hah! I knew you'd read it anyway. Whatever. Cover your eyes at least.

To be honest, people view this topic because they have no idea what a "Disk copier" might be. Of course they have thoughts of fs.copy and the like, but then they dismiss them as unlikely. Who would post an fs.copy wrapper, after all? So with the chance of seeing an fs.copy wrapper put aside, people click on the title of the topic. They read the OP, and think "man, I can't believe this really is a wrapper for fs.copy". They close the tab and are done here.

Then there is your ATARI based game. You give away the contents of your topic with the title (not that that's a bad thing, it's still better than a title that tells us nothing). Some people will go "what? ATARI? ehh, not gonna click on it" immediately.

TL;DR this topic is too mysterious to not be read.
Edited on 02 December 2013 - 04:17 PM
Xenthera #6
Posted 02 December 2013 - 04:41 PM
Still dont get how this is newer then my post and has more views then my ATARI based game, You can just do "copy PROGRAM disk/NEWPROGRAMNAME", This is useless and child's code

That type of attitude is not welcome on this forum.
secret1timb7 #7
Posted 02 December 2013 - 07:00 PM
Still dont get how this is newer then my post and has more views then my ATARI based game, You can just do "copy PROGRAM disk/NEWPROGRAMNAME", This is useless and child's code

That type of attitude is not welcome on this forum.

Sorray im just impationt, i posted that a couple minutes after my game came out, Now my game has like 15K+ views
Coding Brain Activated #8
Posted 04 December 2013 - 04:34 AM
Yeah, actually using the cp command is a bit better, but I hate it because it's disorganized and you are bound to make mistakes if the name is long. Maybe with a few more features in this program, you could make it as good, or even better than the cp command.