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

[Question][Error]Make a formatter for Computer.

Started by Franckf, 18 January 2013 - 07:58 AM
Franckf #1
Posted 18 January 2013 - 08:58 AM
Hello, I made a virus for computer( Computercraft, obliviously :P/>) but now I want to make a formatter. I saw a Disk formatter and I tried to adapt it as a Computer formatter.
The code is this:

sDisk = { ... }
for _, sFile in pairs(fs.list(sDisk[1])) do
fs.delete(sDisk[1] .. "/" .. sFile)
end
I did this:

/ = { ... }
for _, sFile in pairs(/)) do
fs.delete(/ .. "/" .. sFile)
end
But,when I try to start it, it says:
bios:206: [string"formatter"]:1: unexpected symbol
What should I do? I think it can't read the /…
Thanks to all who will try to help me and sorry for any mistakes i did because I'm not English. :)/>
Lyqyd #2
Posted 18 January 2013 - 09:01 AM
/ isn't a legitimate variable name. Use a real variable name instead. Is this for your virus as well?
Franckf #3
Posted 18 January 2013 - 09:04 AM
My virus is a stupid virus xD it is only a lot of programs called edit,delete,lua etc. and i want to add like a keycode to delete all programs :)/>
But…so how could i make a variable for /?Sorry,I'm new with CC and Lua, I'm trying to learn from tutorials xD
remiX #4
Posted 18 January 2013 - 09:13 AM


args = { ... } -- this is known as arguments, and used for when you initilize a program, like tunnel 5 (5 is the args)
for _, sFile in pairs(args) do
  if fs.exists(sFile) then fs.delete(sFile) end -- check if it exists first
end
Franckf #5
Posted 18 January 2013 - 09:23 AM
Em…@RemiX It doesn't give any error but it doesn't delete anything…Why?Thanks anyways both for helping me :D/>
remiX #6
Posted 18 January 2013 - 09:34 AM
Well, it can only delete files within the computer's own folder, not the files within rom.
And you need to type the filename after your call it within the shell, like so:


-- if the program is called 'test'

test filenameOne filenameTwo
Lyqyd #7
Posted 18 January 2013 - 09:46 AM
My virus is a stupid virus xD it is only a lot of programs called edit,delete,lua etc. and i want to add like a keycode to delete all programs

We will not help you write code to be used maliciously. Locked.

Edit: Chatted with OP via PM; apparently topic is asking for help counteracting his "virus". Re-opened.
Luanub #8
Posted 18 January 2013 - 07:45 PM


args = { ... } -- this is known as arguments, and used for when you initilize a program, like tunnel 5 (5 is the args)
for _, sFile in pairs(args) do
  if fs.exists(sFile) then fs.delete(sFile) end -- check if it exists first
end

Isn't this the same thing as using rm, only it will allow you to specify multiple files?

I haven't tested this but it should work to "format" and entire directory at a time, not sure if this is what you are wanting or not.

tArgs = { ... }

for _,dir in pairs(tArgs) do
  local files = fs.list(dir)
  for _,file in pairs(files) do
    if not fs.isReadOnly(dir.."/"..file) then
      fs.delete(dir.."/"..file)
    end
  end
end

If you name the program "format" then to format a disk you would do "format disk". If you wanted to do root then "format /" should work. Like I said I haven't tested this code yet.
theoriginalbit #9
Posted 18 January 2013 - 07:54 PM
id be more inclined to take the arg as the start dir, do a fs.list(), resolve the path, and the delete everything that comes from fs.list at that path…