3 posts
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. :)/>
8543 posts
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?
3 posts
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
2088 posts
Location
South Africa
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
3 posts
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/>
2088 posts
Location
South Africa
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
8543 posts
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.
1111 posts
Location
Portland OR
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.
7508 posts
Location
Australia
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…