-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathfiles.java
45 lines (40 loc) · 1.33 KB
/
files.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
45
package ru.arhiser.file_search;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class files {
public static void main(String[] args) {
ArrayList<File> fileList = new ArrayList<>();
getFiles(new File("D:\\"), fileList);
for(File file: fileList) {
System.out.println(file.getAbsolutePath());
}
}
private static void getFiles(File rootFile, List<File> fileList) {
if (rootFile.isDirectory()) {
System.out.println("searching: " + rootFile.getAbsolutePath());
File[] directoryFiles = rootFile.listFiles();
if (directoryFiles != null) {
for (File file: directoryFiles) {
if (file.isDirectory()) {
getFiles(file, fileList);
} else {
if (file.getName().toLowerCase().endsWith(".jpg")) {
fileList.add(file);
}
}
}
}
}
}
private static void printArray(int[] arr) {
System.out.print("[");
for (int i = 0; i < arr.length; i++) {
if (i > 0) {
System.out.print(", ");
}
System.out.print(arr[i]);
}
System.out.println("]");
}
}