-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFolderTreeDelete.java
More file actions
29 lines (24 loc) · 890 Bytes
/
FolderTreeDelete.java
File metadata and controls
29 lines (24 loc) · 890 Bytes
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
import java.io.File;
public class FolderTreeDelete {
public static String startFolderString = "D:\\Temp\\test22";
public static void main(String[] args) {
listAndRemove(new File(startFolderString));
}
private static void listAndRemove(File parent) {
System.out.println("Entering " + parent.getAbsolutePath());
File[] children = parent.listFiles();
if (children != null) {
for (File child : children) {
if (child.isDirectory()) {
listAndRemove(child);
}
System.out.print("Removing " + child.getAbsolutePath() + " ==> ");
if (child.delete()) {
System.out.println("OK");
} else {
System.out.println("ERROR");
}
}
}
}
}