-
Notifications
You must be signed in to change notification settings - Fork 1
/
Finder.java
42 lines (35 loc) · 1.12 KB
/
Finder.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
package com.yurii.salimov.lesson05.task02;
import java.io.File;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public class Finder {
private final String dirName;
private final Criterion criterion;
public Finder(final String dirName, final Criterion criterion) {
this.dirName = dirName;
this.criterion = criterion;
}
public void findAndPrint() {
recursionFindAndPrint(this.dirName);
}
private void recursionFindAndPrint(final String dirName) {
final File[] fileList = new File(dirName).listFiles();
if (fileList != null) {
for (File file : fileList) {
if (file != null) {
if (this.criterion.check(file)) {
println(file);
}
if (file.isDirectory()) {
recursionFindAndPrint(file.getPath());
}
}
}
}
}
private static void println(final File file) {
System.out.println((file.isFile() ? "File: " : "Directory: ") + file.getPath());
}
}