68 posts
Posted 24 March 2012 - 01:30 PM
I am creating an Anti-Virus and need some assistance..
f = io.open("startup","w")
f:write("")
f:close()
print("All Infected Files Removed From System!")
print("System will now reboot!")
disk.eject(right)
sleep(3)
os.reboot()
I am getting an error code for line 3 stating:
disk:3: bad argument: string expected, got nilAny one know the problem here? I am sure it is something simple, but I just can't see it! D:
715 posts
Posted 24 March 2012 - 01:43 PM
You have to put the side-argument for
disk.eject into double-quotes, because it has to be a string.
So rather than…
disk.eject(right)
… do this:
disk.eject("right")
68 posts
Posted 24 March 2012 - 01:46 PM
Thanks! I feel like I am becoming a regular face on this 'Ask a Pro' forum xD
715 posts
Posted 24 March 2012 - 02:07 PM
No problem, and the more you get to know, the less you'll have to ask in the future.
So I see no problem in being a regular face here, it only helps to further your understanding. :(/>/>
Also, btw.:
If your aim is only to clear out the startup file in case there is a virus in there, then - alternatively - you could just delete it, saving you a few lines of code:
fs.delete("startup")
724 posts
Posted 24 March 2012 - 05:37 PM
and antivirus should not wait to reboot
715 posts
Posted 24 March 2012 - 05:41 PM
and antivirus should not wait to reboot
I think he's doing a sleep there so that a user has time to read the message. :(/>/>
68 posts
Posted 24 March 2012 - 05:45 PM
and antivirus should not wait to reboot
I think he's doing a sleep there so that a user has time to read the message. :(/>/>
Yeah xD
And thanks for the tip, but normally when I do fs.delte it was say that I'm not allowed or something along those lines :S
715 posts
Posted 24 March 2012 - 07:37 PM
and antivirus should not wait to reboot
I think he's doing a sleep there so that a user has time to read the message. :(/>/>
Yeah xD
And thanks for the tip, but normally when I do fs.delte it was say that I'm not allowed or something along those lines :S
That can have two reasons:
- You tried to delete something from the /rom folder, or…
- … you didn't properly close a file you had opened previously and tried to delete that.
If it's the second case, then you can only delete it after a reboot.
And remember to always make sure that files are being closed properly before a program ends.
During development it can happen that a program terminates because of an error before you were able to close it. Then you have no choice to reboot.
Also I think this problem only exists for either fs.open() or io.open(). I can't remember which one, but I think it was only one of them that had this problem.
I'm about 80% sure it was io.open().But regardless, always close your files. :)/>/>
EDIT:
Ok, just had a few test-runs about my last (now striked-out) paragraph.
The "access denied" occurs definitely with both of them, since fs.delete() is trying to delete a file that's still mounted and thus marked as "read-only".
So never forget to do what the last sentence above this edit tells you to do.^^
Edited on 24 March 2012 - 07:39 PM