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

Weird error?

Started by IndustrialLemon, 04 November 2018 - 07:19 AM
IndustrialLemon #1
Posted 04 November 2018 - 08:19 AM
Hey! Me again. Sorry for the incessant posts but I just can't get enough of lua! Been programming my butt off.

Here's the code.
Spoiler

ID = os.getComputerID()
os.setComputerLabel("CnS_Turtle_"..ID)
verify = fs.list("")
disk_commandList = fs.list("disk/CnS")
--verify that there is or is not a CnS directory
for i = 1, #verify do
	if verify[i] == "CnS" then
		term.clear()
		term.setCursorPos(1,1)
		print(" ...CnS Turtle Successfully booted...")
		print("Turtle ID is "..ID..".")
		print("Please issue a command in order to begin.")
		print("Type \"prog\" to see the list of loaded applications and type \"auto\" to setup automation.")
		break
	else
		--install CnS package
		for i = 1, #disk_commandList do
			fs.copy("disk/CnS/"..disk_commandList[i], "CnS/"..disk_commandList[i])		
		end
		os.reboot()	  
	end
end
  
commandList = fs.list("CnS")		  
function commandPrompt()
	command = io.read()
	for i = 1, #commandList, 1 do
		if command..".lua" == commandList[i] then
		  
			if command == "terminal" then
				return os.run({}, "CnS/terminal.lua")
	  
			elseif command == "auto" then
				return os.run({}, "CnS/auto.lua")
		  
			else
				print("*You issued the "..command.." command.*")
				os.run({}, "CnS/"..command..".lua")
				return commandPrompt()
			end
		end
	end
	print("Not a valid command.")
	sleep(.5)
	return commandPrompt()
end
commandPrompt()

The error I receive when first running the code on a blank computer is this.

startup.lua:19: auto.lua: File Exists
The idea is to be installing a load of programs from the disk/CnS/ dir onto the turtle that's parked by the disk drive.
Afterward, if I check the list of programs under the CnS/ dir, auto.lua is the only one showing up.
There should be a few more than that.
I believe it's attempting to copy the program twice which is producing the error but I cannot for the life of me figure out where it's doing that? I need an extra pair of eyes if anyone is willing to take a look.

Thank you!

OH and don't get the wrong idea I still need help with my other posts! I've got a bunch of different projects that I'm bouncing between.

EDIT:
I've patched my bug but I'm not sure if this is the roundabout way or the exact way I needed to do it.
In order to fix it I simply put fs.delete("CnS/"..disk_commandList) right before the fs.copy(…) and that seems ot have fixed it.
Edited on 04 November 2018 - 07:29 AM
Lupus590 #2
Posted 04 November 2018 - 10:27 AM
The issue is that fs.copydoesn't like to overwrite files and you told it to do that, by deleting first you make sure that the file won't exist.
IndustrialLemon #3
Posted 04 November 2018 - 06:53 PM
I understand that much but I'm still confused because when I would do 'delete CnS/' manually before updating it would still produce that error. Am I just blind?
KingofGamesYami #4
Posted 04 November 2018 - 09:46 PM
There is no functional difference between deleting inside a program and deleting manually.