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

Overwriting fs.open, keeps getting File Not Found. [SOLVED]

Started by ComputerCraftFan11, 11 June 2012 - 02:52 AM
ComputerCraftFan11 #1
Posted 11 June 2012 - 04:52 AM
I tried to overwrite fs.open so I can edit .rom but I keep getting "File not found" when I type anything in the CraftOS shell.

This is my current code:

if not fs.exists(".rom") then
fs.copy("rom", ".rom")
end
oldfsopen = fs.open
function testOpenWithRomEditor( _fPath, _fMode )
if _fPath and _fMode then
  if string.find( _fPath, "rom") and not string.find( _fPath, ".rom") then
   _fPath = string.gsub( _fPath, "rom", ".rom")
  end

  oldfsopen( _fPath, _fMode )
end
end
fs.open = testOpenWithRomEditor

EDIT:
Solved, I never returned oldfsopen
Edited on 11 June 2012 - 05:15 AM
ComputerCraftFan11 #2
Posted 11 June 2012 - 06:35 AM
I posted a formatted version.
http://pastebin.com/kYwg9ERb

If you wanna see the error, save that program as startup and reboot.

Now try to run a program.
archit #3
Posted 11 June 2012 - 06:54 AM
I tried to overwrite fs.open so I can edit .rom but I keep getting "File not found" when I type anything in the CraftOS shell.

This is my current code:

fs.copy("rom", ".rom")
I would first suggest adding in the path to where you are copying the rom dir. If it is going to reside in your base directory then add a / in front of .rom. As well you will want to add in the path on your fs.exists at the start of your code. You will also want to add the / in front of rom, so if the program is run from a different location it can also find that as well. As it stands now, it is searching for a file/directory "rom" in the current folder that you are running your code from.

A big problem is that you are trying to copy a directory to a name starting with a . To my knowledge the filesystem will not allow this and it will never be created. I would always steer clear away from non-standard naming conventions when naming folders on any file structure.

Lastly, no clue if this is relevant, but there is a bug with string.find in computercraft. Here is a link I came across about it http://www.computerc...d-twice-bugged/
ComputerCraftFan11 #4
Posted 11 June 2012 - 07:01 AM
I tried to overwrite fs.open so I can edit .rom but I keep getting "File not found" when I type anything in the CraftOS shell.

This is my current code:

fs.copy("rom", ".rom")
I would first suggest adding in the path to where you are copying the rom dir. If it is going to reside in your base directory then add a / in front of .rom. As well you will want to add in the path on your fs.exists at the start of your code. You will also want to add the / in front of rom, so if the program is run from a different location it can also find that as well. As it stands now, it is searching for a file/directory "rom" in the current folder that you are running your code from.

A big problem is that you are trying to copy a directory to a name starting with a . To my knowledge the filesystem will not allow this and it will never be created. I would always steer clear away from non-standard naming conventions when naming folders on any file structure.

Lastly, no clue if this is relevant, but there is a bug with string.find in computercraft. Here is a link I came across about it http://www.computerc...d-twice-bugged/

Here are some things:
  1. The fs.copy has nothing to do with the error
  2. Files do not have to have a / in the beginning
  3. If a file has a . in the beginning, it will work but not be shown on fs.list
  4. The string.find doesn't cause this to error, you don't even need to add a string.find either.
  5. The error is INSIDE of the fs.copy i made.
archit #5
Posted 11 June 2012 - 07:12 AM
So the rom your trying to find is a file not a directory?
ComputerCraftFan11 #6
Posted 11 June 2012 - 07:12 AM
@Above: It is a directory.

Oops, i think i noticed my error.

I never returned the original fs.open.

PROBLEM SOLVED!
archit #7
Posted 11 June 2012 - 07:18 AM
If your just going to use this in the main directory, and never anywhere else then your fine, but otherwise you need the path, by adding the / for the base directory.

i.e. if you put this program into a directory called mine that resides in the base dir .. so /mine/your_program_name then it will never see the rom directory as its not in /mine/rom its in /rom

When dealing with file paths, it is always good to put the full path, and never just assume it will be run only from that one location as a program.
MysticT #8
Posted 12 June 2012 - 01:24 AM
If your just going to use this in the main directory, and never anywhere else then your fine, but otherwise you need the path, by adding the / for the base directory.

i.e. if you put this program into a directory called mine that resides in the base dir .. so /mine/your_program_name then it will never see the rom directory as its not in /mine/rom its in /rom

When dealing with file paths, it is always good to put the full path, and never just assume it will be run only from that one location as a program.
Actually, the fs api functions use absolute paths, so you don't need that. But this could be changed, it's good to use full paths when you can, just to be sure.