-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileStruct.java
More file actions
47 lines (37 loc) · 1.06 KB
/
FileStruct.java
File metadata and controls
47 lines (37 loc) · 1.06 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
39
40
41
42
43
44
45
46
47
import java.io.File;
import java.util.*;
/**
* Uses a recursive function to find all the terminal folders
* and returns them in an arrayList of Strings.
*/
class FileStruct {
FileStruct() {}
public static void main(String[] args){
String str = System.getProperty("user.dir");
ArrayList<FileTree> dirs = new ArrayList<FileTree>();
dirs = getFilePath(str);
//Set<String> set = new HashSet<String>(dirs);
//System.out.println(set);
System.out.println(dirs.size());
for (int i=0; i<dirs.size(); i++){
System.out.println(dirs.get(i).getChildren());
}
}
public static ArrayList<FileTree> getFilePath(String dir){
File path = new File(dir);
File[] files = path.listFiles();
FileTree ft = new FileTree();
ft.setParent(dir);
ArrayList<String> children = new ArrayList<String>();
ArrayList<FileTree> trees = new ArrayList<FileTree>();
for (File file : files){
if (file.isDirectory()){
children.add(file.toString());
trees.addAll(getFilePath(file.toString()));
}
}
ft.setChildren(children);
trees.add(ft);
return trees;
}
}