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

"File not found"

Started by GlassOS, 13 November 2014 - 05:30 PM
GlassOS #1
Posted 13 November 2014 - 06:30 PM
Hello, I am trying to write a getVersion() function but there is an error I don't know where though here is the code
Error I get:
File Not Found

Code:

function getVesion()
  fl = fs.open("files/version","a"
  if fs.exists("files/version") then  
  version = file.readLine()
  print(version)
  else
    print("GlassOS is not installed or you have deleted the 'Version' file.")
end
files/version File Contains

4.0
Edited on 13 November 2014 - 05:30 PM
martijnenco #2
Posted 13 November 2014 - 06:37 PM
function getVesion()
if fs.exists("files/version") then
  file = fs.open("files/version","a")
  version = file.readLine()
  print(version)
else
  print("GlassOS is not installed or you have deleted the 'Version' file.")
end
end

You forgot to close fs.open() with an ")" and you shouldt have done it with another order in lines.
Also..
FILE.readLine()
should be the same as
FILE = fs.open("files/version","a")
This should be better (Dont blame if it is not. I didn't test it…
Edited on 13 November 2014 - 05:43 PM
GlassOS #3
Posted 13 November 2014 - 06:44 PM
[color=#000088]function[/color][color=#000000] getVesion[/color][color=#666600]()
[/color]  if.fs.exists("files/version") then
[color=#000000]	fl = fs.open("files/version","a")[/color][color=#000000]
	version [/color][color=#666600]=[/color][color=#000000] file[/color][color=#666600].[/color][color=#000000]readLine[/color][color=#666600]()[/color]
[color=#000000]	[/color][color=#000088]print[/color][color=#666600]([/color][color=#000000]version[/color][color=#666600])[/color]
[color=#000000]  [/color][color=#000088]else[/color]
[color=#000000]	[/color][color=#000088]print[/color][color=#666600]([/color][color=#008800]"GlassOS is not installed or you have deleted the 'Version' file."[/color][color=#666600])
[/color]  end
[color=#000088]end[/color]

You forgot to close fs.open() with an ")" and you shouldt have done it with another order in lines.
This should be better (Dont blame if it is not. I didn't test it…
No it wasn't that was a copy & paste error :3

Here is the updated source but now im getting the error
"Attempted to Call nil on line 3"

if fs.exists("files/version") then  
file = fs.open("files/version","a")
var = file.readLine()
print(var)
else
print("GlassOS is not installed or you have deleted the 'Version' file.")
end
Edited on 13 November 2014 - 05:44 PM
martijnenco #4
Posted 13 November 2014 - 06:50 PM
Try to change the "a" in "r" in the fs.open() function that should do the trick.


Copy'd from the computercraft wiki
  • "r" to open the file read-only,
  • "w" to open it for writing and remove any existing data on file open, or
  • "a" to open for writing but keep existing data and append any writes to the end of the file
Edited on 13 November 2014 - 05:52 PM
GlassOS #5
Posted 13 November 2014 - 06:53 PM
Try to change the "a" in "r" in the fs.open() function that should do the trick.


Copy'd from the computercraft wiki
  • "r" to open the file read-only,
  • "w" to open it for writing and remove any existing data on file open, or
  • "a" to open for writing but keep existing data and append any writes to the end of the file
Didn't work now it just prints an empty line :3
martijnenco #6
Posted 13 November 2014 - 07:02 PM
That's wierd, it works for me..
Try to use file.readAll()
If that doesn't work I have no clue what to do next..