You don't need to find all partitions. First of all, not all partitions have file systems. Instead, you need to find all logical drives. This is how:
DriveInfo.GetDrives Method (System.IO)[
^].
Instead of the method
Directory.GetFiles
, you can use another
Directory.GetFiles
method which finds files recursively:
Directory.GetFiles Method (String, String, SearchOption) (System.IO)[
^].
Your code is buggy, so it can be one of the reasons why the file is not deleted, or even not found. The worst thing is exception handling. You block exception propagation, and only show the some
Error
, which is not exception information. You simply hide exceptions.
Just write your code accurately, run it under the debugger to see how it works and to eliminate bugs, test it well.
—SA