-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileTree.java
36 lines (30 loc) · 1 KB
/
FileTree.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
// KEJ-FileTree/FileTree.java
// Taha Burak Sahin PJATK
import java.io.File;
public class FileTree {
public static void main(String[] args) {
File file = (args.length == 0) ?
new File(System.getProperty("user.dir")).
getParentFile().getParentFile()
: new File(args[0]);
getList(file,"");
}
private static void getList(File dir, String skip) {
// indentation
System.out.print(skip);
System.out.println("[" + dir.getName() + "]");
skip = skip + " ";
// list of files from a directory
File[] lis = dir.listFiles();
for (File file : lis) {
if (file.isFile()) {
System.out.print(skip);
System.out.println(" " + file.getName());
}
}
// go recursively into directories
for (File file : lis)
if (file.isDirectory())
getList(file,skip);
}
}