Jump to content




Help


  • You cannot reply to this topic
5 replies to this topic

#1 Leon669

  • Members
  • 57 posts
  • LocationGermany

Posted 20 February 2015 - 08:17 PM

How can i delete the hole text of a file with fs.open?

#2 InDieTasten

  • Members
  • 357 posts
  • LocationGermany

Posted 20 February 2015 - 08:20 PM

local fh = fs.open("pathtofiletodelete", "w")
fh.close()
? Not sure, but it'll do what I interpret of your question

Edited by InDieTasten, 20 February 2015 - 08:23 PM.


#3 Quintuple Agent

  • Members
  • 107 posts
  • LocationThis page

Posted 20 February 2015 - 08:21 PM

Well, first of all, you can use fs.delete to delete a file, but if you must use fs.open, doing fs.open(file,"w") will open it in write mode, which means the file is cleared and whatever is written to it using fs.write() or fs.writeLine() will be the only data in the file, so if you were to do
a=fs.open(file,"w")
a.close()
That would effectively delete the contents of the file, however the file will still be there, just nothing in it.

#4 Leon669

  • Members
  • 57 posts
  • LocationGermany

Posted 20 February 2015 - 08:28 PM

View PostQuintuple Agent, on 20 February 2015 - 08:21 PM, said:

Well, first of all, you can use fs.delete to delete a file, but if you must use fs.open, doing fs.open(file,"w") will open it in write mode, which means the file is cleared and whatever is written to it using fs.write() or fs.writeLine() will be the only data in the file, so if you were to do
a=fs.open(file,"w")
a.close()
That would effectively delete the contents of the file, however the file will still be there, just nothing in it.

Thanks that was that iam searching for.

#5 Leon669

  • Members
  • 57 posts
  • LocationGermany

Posted 20 February 2015 - 09:24 PM

shell.run"cd //"
file = fs.open("loginSettings/curUser", "r")
version = file.readLine()
file.close()
term.setCursorPos(1,9)
print(version)
shell.run"cd //"
shell.run"cd OS"

get an error by reading a file
attempt to index? a nil value

#6 InDieTasten

  • Members
  • 357 posts
  • LocationGermany

Posted 20 February 2015 - 09:34 PM

I would imagine your file "loginSettings/curUser" doesn't exist, therefor your variable file will be nil, and next line you are attempting to index this nil variable via .readLine Which leads to error at that point. Make sure the file is existing or/and check the variable to not be nil, before indexing it.

Also note, that you are giving a relative path to fs.open meaning running your script from another location will lead in another resolved path. So you might want to change it to an absolute path by anchoring it to the root of the filesystem: "/loginSettings/curUser"

Edited by InDieTasten, 20 February 2015 - 09:36 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users