-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathFileWalker.java
More file actions
48 lines (35 loc) · 1.34 KB
/
FileWalker.java
File metadata and controls
48 lines (35 loc) · 1.34 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
48
package org.utplsql.cli;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Vinicius on 18/06/2017.
*/
public class FileWalker {
public List<String> getFileList(File baseDir, String inspectPath) {
return getFileList(baseDir, inspectPath, true);
}
public List<String> getFileList(File baseDir, String inspectPath, boolean relative) {
File inspectDir = new File(baseDir, inspectPath);
if (!inspectDir.isDirectory())
throw new IllegalArgumentException(inspectPath + " is not a directory.");
List<String> fileList = new ArrayList<>();
listDirFiles(baseDir, inspectDir, fileList, relative);
return fileList;
}
private void listDirFiles(File baseDir, File directory, List<String> fileList, boolean relative) {
File[] directoryFiles = directory.listFiles();
if (directoryFiles == null)
return;
for (File file : directoryFiles) {
if (file.isFile()) {
String absolutePath = file.getAbsolutePath();
if (relative)
absolutePath = absolutePath.substring(baseDir.getAbsolutePath().length() + 1);
fileList.add(absolutePath);
} else {
listDirFiles(baseDir, file, fileList, relative);
}
}
}
}