-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocateEx.java
42 lines (41 loc) · 994 Bytes
/
LocateEx.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
import java.io.File;
public class LocateEx
{
private String fileEx;
private File directoryName;
private File searchDir;
private File[] pathNames;
private String outputString = "Find extention: ";
private boolean exFound = false;
public LocateEx(String fileEx, String directory) throws NullPointerException
{
this.fileEx = fileEx;
this.directoryName = new File(directory);
outputString += fileEx+"\n";
fileSearch(fileEx, directoryName);
}
private void fileSearch(String fileEx, File directoryName)
{
String filePath = "No Files Found\n";
pathNames = directoryName.listFiles();
for (File path: pathNames)
{
if(path.isDirectory())
fileSearch(fileEx,path);
else if(path.getName().endsWith(fileEx))
{
filePath = (path.getAbsolutePath()+"\n");
outputString += filePath;
exFound = true;
}
}
}
public String getOutput()
{
if (!exFound)
{
outputString +="Extention Not Found\n";
}
return outputString;
}
}