-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasic_FolderDeleter.java
44 lines (33 loc) · 1.17 KB
/
Basic_FolderDeleter.java
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
39
40
41
42
43
44
//2019 Java Learning Repo
//Basic Folder Deleter V1
//written by rwx777
import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Scanner;
public class Basic_FolderDeleter {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Please enter Directory Path: ");
Path rootPath = Paths.get(reader.nextLine());
try {
final long startTime = System.currentTimeMillis();
Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS)
.sorted(Comparator.reverseOrder())
.map(Path::toFile) //.peek(System.out::println)
.forEach(File::delete);
final long endTime = System.currentTimeMillis();
long MillisTook = (endTime - startTime);
double SecondsTook = ((endTime - startTime) / 1000);
System.out.println("Deleted Folder " + rootPath + " succesfully");
System.out.println("Total time: " + SecondsTook + "s or " + MillisTook + "ms"); //prints out time it took
}catch (IOException e) {
e.printStackTrace();
}
reader.close();
}
}