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

fs.copy bug? Please help

Started by 9TYNINE, 29 December 2017 - 02:28 PM
9TYNINE #1
Posted 29 December 2017 - 03:28 PM
OK so firstly I'm using craftOS 1.7
I am trying to copy from my computer to my pocket computer and used the following code:
fs.copy("9tyninecraft","disk/test")
And I got File already exists although there is no program called test on either computer
Nothy #2
Posted 29 December 2017 - 08:16 PM
Check whether or not a file called disk/test exists, it might've just created a folder somewhere
KingofGamesYami #3
Posted 29 December 2017 - 08:18 PM
Try the cp program. If that works then we can continue debugging your program after you post the full code.
9TYNINE #4
Posted 30 December 2017 - 03:23 AM
I am running it in a program I think it is because I didn't wrap my peripheral
Luca_S #5
Posted 30 December 2017 - 08:33 AM
I am running it in a program I think it is because I didn't wrap my peripheral

That shouldn't be a problem the shell automatically adds the /disk folder.
Could it be that you have multiple drives connected and your Pocket PC is in /disk2 or something like that?

EDIT: Also remember that fs.copy takes file paths relative to the root, not to your current shell directory. This means if your program is in /folder and you run fs.copy("a", "b") it will copy /a to /b and not /folder/a to /folder/b
Edited on 30 December 2017 - 07:36 AM
9TYNINE #6
Posted 01 January 2018 - 06:35 AM
Cool thanks that fixes that now I can't delete it it keeps telling me that it wants a string even if I put
fs.delete("startup","disk2")
9TYNINE #7
Posted 01 January 2018 - 06:45 AM
Furthermore it will work for my pocket computer but if I use a turtle it give a attempt to concatenate nil and string
9TYNINE #8
Posted 01 January 2018 - 07:00 AM
yeah this is kinda getting annoying can you have a look at my code look through lines 116-128 and 95-100

if term.isColor() == true then
  BgC = colors.blue
  BdC = colors.green
elseif term.isColor() == false then
  BgC = colors.black
  BdC = colors.white
end

Padges = {{"World Eater","Sorting","Move",
  "Games","Calculator","Disk","Options","Help","Exit"},
		 {"Start","Help","Exit"},{"Check Disk","Startup","9TYNINECRAFT","Calculator","Help","Exit"}}
PdN = 1
CuS = 0
TxC = colors.white
ScW,ScH = term.getSize()
Running = true

function Padge()
  term.setBackgroundColor(BgC)
  term.clear()
  term.setBackgroundColor(BdC)
  term.setCursorPos(1,1)
  for i = 1,ScW do
	term.write(" ")
  end
  for i = 2,ScH do
	term.setCursorPos(1,i)
	term.write(" ")
	term.setCursorPos(ScW,i)
	term.write(" ")
  end
  term.setCursorPos(1,ScH)
  for i = 1,ScW do
	term.write(" ")
  end	  
  term.setCursorPos(2,2)
  term.setBackgroundColor(BgC)
end

function List()
  term.setCursorPos(2,2)
  MaxN = table.maxn(Padges[PdN])
  for i = 1,MaxN do
	row = i
	CurentPadge = Padges[PdN]
	Hlght()
	term.write(CurentPadge[i])
	term.setCursorPos(2,i+2)
  end
end

function SeL()
  p1,p2 = os.pullEvent()
  if p2 == 208 then
	if CuS ~= MaxN then
	  CuS = CuS+1
	elseif CuS == MaxN then
	  CuS = 1
	end
  elseif p2 == 200 then
	if CuS > 1 then
	  CuS = CuS-1
	else
	  CuS = MaxN
	end
  elseif p2 == 28 then
	if PdN == 1 then
	  if CuS == 1 then
		Padge()
		PdN = 2
		CuS = 0
	  elseif CuS == 5 then
		shell.run("Calculator")
	  elseif CuS == 6 then
		Padge()
		PdN = 3
		CuS = 0
	  elseif CuS == MaxN then
		Running = false
	  end
	elseif PdN == 2 then
	  if CuS == 1 then
		WorldEater()
	  elseif CuS == MaxN then
		Padge()
		PdN = 1
		CuS = 1
	  end
	elseif PdN == 3 then
	  if CuS == 1 then
		Padge()
		Check_Disk()
		sleep(2)
	  elseif CuS == 2 then
		--fs.delete("startup","disk2")
		fs.copy("startup",DiskM.."/startup")
	  elseif CuS == 3 then
		fs.copy("9TYNINECRAFT",DiskM.."/9TYNINECRAFT")
	  elseif CuS == 4 then
		fs.copy("Calculator",DiskM.."/Calculator")
	  end
	end
  end
end

function Hlght()
  if CuS == row then
	term.setBackgroundColor(colors.white)
	term.setTextColor(colors.black)
  elseif CuS ~= i then
	term.setBackgroundColor(BgC)
	term.setTextColor(TxC)
  end
end

function Check_Disk()
  Padge()
  term.write("What Side is your disk drive on? ")
  Disk = peripheral.wrap(io.read())
  if Disk.isDiskPresent() then
	Padge()
	DiskM = Disk.getMountPath()
	term.write("Disk found")
  else
	Padge()
	term.write("No disk found")
  end
end

sleep(.5)
Padge()
List()
while Running do
List()
SeL()
--term.setCursorPos(7,7)
--term.write(MaxN)
--term.setCursorPos(8,8)
--term.write(CuS)
sleep(.15)
end
term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)
term.clear()
term.setCursorPos(1,1)
term.write("Thank you for using 9TYNINECRAFT")
term.setCursorPos(1,2)



sorry that i couldn't put my code in a spoiler
Edited on 01 January 2018 - 06:05 AM
Luca_S #9
Posted 01 January 2018 - 10:01 AM
Cool thanks that fixes that now I can't delete it it keeps telling me that it wants a string even if I put
fs.delete("startup","disk2")

This is not how fs.delete works.
It only takes 1 Argument and that is the path to delete, so it should be:

fs.delete("disk2/startup")

Your Problem with nil is that variables in Lua(And most other programming languages) are only defined for the current scope(Meaning the current if, else, while, function, etc.)
So your DiskM is only defined in the if block in the Check_Disk() function. I would suggest you make it available in your whole program by putting this at the top:

local DiskM
9TYNINE #10
Posted 01 January 2018 - 12:54 PM
Cool thanks for reminding me to set up variables at the beginning of my program
9TYNINE #11
Posted 03 January 2018 - 12:15 AM
would fs.delete(DiskM.."/startup") be the correct phrasing

also how do i run a pastebin from a program
Edited on 02 January 2018 - 11:39 PM
Luca_S #12
Posted 03 January 2018 - 08:32 AM
would fs.delete(DiskM.."/startup") be the correct phrasing

also how do i run a pastebin from a program
I would suggest using fs.combine

To run a program from pastebin inside of a program you have different options. The easiest one is to use shell.run, this will however output stuff that you might not want on the screen:

shell.run("pastebin run <code>")
The other way would be to download the program using the http api and execute it:

if not http then --Check if http API is enabled
  error("HTTP needs to be enabled!")
end
local handle = http.get("http://pastebin.com/raw/<code>") --Get the data from pastebin
local content = handle.readAll() --Read everything from the web page
handle.close() --Close the handle
loadstring(content)()
--Loadstring can make a function out of the lua source code
9TYNINE #13
Posted 04 January 2018 - 12:07 AM
I got it I just thought I tried it at some point and it didn't work
9TYNINE #14
Posted 23 January 2018 - 01:40 AM
Cool thanks for all your help