Suppose I wish to make a preliminary decision on whether to delete a folder (using a recursive algorithm that will probably manage to delete some files even if the user stupidly tries to delete c:\windows
). This is more as a shield for user stupidity rather than some form of automated deletion. I don't care if it disallows deleting stuff that advanced users might want to delete. Some thoughts I've had on detecting that deleting a folder is a bad idea:
If folder to be deleted is or contains any folder within
Environment.GetFolderPath(Environment.SpecialFolder.*)
If folder to be deleted is or is within
Environment.GetEnvironmentVariable("systemroot");
If
DirectoryInfo
attributes indicate the directory is a system directory, though I'm not sure that's really used. I do know that on directories, the read-only attribute has been co-opted for other purposes, which is kind of annoying, actually.
Are there any other tests I can do?