I use this solution to delete all empty folders and subdirectories in a specific path:
static void Main(string[] args) { processDirectory(@"c:\temp"); } private static void processDirectory(string startLocation) { foreach (var directory in Directory.GetDirectories(startLocation)) { processDirectory(directory); if (Directory.GetFiles(directory).Length == 0 && Directory.GetDirectories(directory).Length == 0) { Directory.Delete(directory, false); } } }
It works great. But I want to delete all empty folders, as well as folders that are not empty, but also do not contain files with the extension .dvr .
For example, in my folder there are files:
a.log
b.log
c.dvr
d.dat
Therefore, this folder cannot be deleted because it contains a file with the dvr extension.
How can I filter it? (I use GTK #, but I believe that C # code will work as this solution is C # code)
source share