-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearcher.java
More file actions
75 lines (54 loc) · 1.75 KB
/
Searcher.java
File metadata and controls
75 lines (54 loc) · 1.75 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.*;
import java.io.*;
public class Searcher {
private static String filepath = null;
//private static String filepath = "/";
//C:\\Users\\3 Embed\\Desktop\\EzeTap\\Files_Search_RD\\sample_text
private static final String defaultPath = "C:\\Users\\3 Embed\\Desktop\\EzeTap\\Files_Search_RD\\sample_text";
private Searcher() {
this.filepath = defaultPath;
}
private Searcher(String dir) {
if (dir.isEmpty()) {
this.filepath = defaultPath;
} else {
this.filepath = dir;
}
}
public static void main(String[] args) throws IOException {
Searcher search = new Searcher();
String toSearch="";
String folderToSearch = search.filepath;
System.out.println("Folder name "+folderToSearch);
File folder = new File(folderToSearch);
Set<File> list = new HashSet<File>();
search.getFiles(folder, list);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input the String to Search: ");
try {
toSearch = br.readLine();
//System.out.println("Searching in 4 files: "+searchFiles(input));
} catch(Exception e) {
e.printStackTrace();
}
//Print Set elements
Iterator iter = list.iterator();
while (iter.hasNext()) {
System.out.println(iter.next());
}
for (File file : list) {
BruteForceSearch bSerch = new BruteForceSearch(file);
bSerch.search(toSearch);
}
}
private void getFiles(File folder, Set<File> list) {
folder.setReadOnly();
File[] files = folder.listFiles();
System.out.println("Files length inside folder "+files.length);
for (int j = 0; j < files.length; j++) {
list.add(files[j]);
if (files[j].isDirectory())
getFiles(files[j], list);
}
}
}