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

Acces Denied...

Started by xdxder, 17 November 2013 - 06:54 AM
xdxder #1
Posted 17 November 2013 - 07:54 AM
Hey.
I made a Program that remove all files on the Computer.
But there is one Problem….the ROM-Folder…
The Program works, it delete all files on the computer but it also try to delete the rom-folder.



Can i make a program that remove all files but that don't try to remove the rom-folder?
The Code…

function rmall()
shell.run("clear")
list = fs.list("/")
anzahl = #list
zaehler = 0
print("Do you really want to remove all files?")
write("Y/N>")
eingabe = read()
if eingabe == "Y" then
  while zaehler <= anzahl do
	fs.delete(tostring(list[zaehler]))
	zaehler = zaehler + 1
  end
elseif eingabe == "N" then
  print("canceled...")
  sleep(2)
  shell.run("disk/startup")
else
  print("What?")
  sleep(2)
  rmall()
end

(its not the whole script, only the function)
Ziriee #2
Posted 17 November 2013 - 02:27 PM

while zaehler <= anzahl do
  if tostring(list[zaehler]) ~= "rom" then
	fs.delete(tostring(list[zaehler]))
  end
  zaehler = zaehler + 1
end

Try that. It will check if it's trying to remove the rom.
Edited on 17 November 2013 - 01:27 PM
Agoldfish #3
Posted 17 November 2013 - 04:40 PM
Here, this is what you want to remove all non-read only files.

for _, f in pairs(fs.list("/")) do
    if not fs.isReadOnly(f) then
	  fs.delete(f)
    end
  end
end

xdxder #4
Posted 18 November 2013 - 11:59 AM
Thanks.
I'll try it.
Edited on 19 November 2013 - 09:45 AM
Agoldfish #5
Posted 20 November 2013 - 12:17 PM
Thanks.
I'll try it.
Did it work?