-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderTree.cs
More file actions
38 lines (37 loc) · 1.16 KB
/
FolderTree.cs
File metadata and controls
38 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.IO;
using System.Text;
namespace ShwaTech {
public class FolderTree {
private DirectoryInfo _root;
private FolderTree() { }
public FolderTree( string path ) { _root = new DirectoryInfo( path ); }
public bool Quiet { get; set; } = false;
public void Prune()
{
PruneRecursive(_root);
}
private void PruneRecursive( DirectoryInfo root ) {
var subs = root.GetDirectories();
foreach( var s in subs ) {
PruneRecursive( s );
}
if( subs.Length > 0 ) {
subs = root.GetDirectories();
}
if( subs.Length <= 0 ) {
var files = root.GetFiles();
if( files.Length <= 0 ) {
try {
if( !Quiet ) Console.WriteLine( "{0}", root.FullName );
root.Delete();
} catch {
// Directory not empty
}
}
} else {
// Directory not empty
}
}
}
}