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

How to blacklist certain items

Started by _removed, 17 December 2014 - 05:12 PM
_removed #1
Posted 17 December 2014 - 06:12 PM
Hello everyone,


I've been working on an OS thats going to be published soon but I need some help with fs.delete(). I am making a systemWipe program that wipes all the files and folders on the system but I need to blacklist certain items like the "rom" directory and other things. This is my code so far:

[attachment=2012:postImg.JPG]

I have the blacklist table, but I don't know how to implement it. I was looking at the OneOS blacklist but that never worked and I wanted some help of you guys so I can get this bleedin systemWipe program sorted.

Your most and humble servant,

smigger22
SquidDev #2
Posted 17 December 2014 - 06:28 PM
My suggestion would be to use the blacklist as a lookup stead:


local blacklist = {
  ['rom'] = true,
}

This means you can do this:

for _, file in ipairs(files) do
  if not blacklist[file] and not blacklist['/'..file] then
    fs.delete(file)
  end
end

This will only work if the path exactly the same (so thing/rom will still be deleted).
_removed #3
Posted 17 December 2014 - 06:51 PM
Thx SquidDev, been waiting a long time for an answer while working on the other aspects of my OS
MKlegoman357 #4
Posted 17 December 2014 - 09:18 PM
You should also check if the folder or file you are trying to delete is read-only or not. That actully would save you from trouble adding rom to the whitelist and trying to figure out if there is a disk drive connected.
_removed #5
Posted 19 December 2014 - 09:49 PM
Thx for the feedback, the OS will now be published soon!!!