-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchMachine.java
More file actions
119 lines (93 loc) · 1.85 KB
/
SearchMachine.java
File metadata and controls
119 lines (93 loc) · 1.85 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.util.Scanner;
import java.io.*;
public class SearchMachine
{
Scanner scan = new Scanner(System.in);
String drives[] = {"C:/", "D:/", "E:/", "F:/","G:/","H:/","I:/"};
String fileName;
int driveIndex;
String files[], innerFiles[];
int flag=0, flag2=0;
File f1, f2, f3;
int i=0,j=0,k=0,l=0, m=0;
public void getFileName()
{
System.out.println("ENTER THE FILE or FOLDER NAME : ");
fileName = scan.nextLine();
}
public void getLocation()
{
System.out.println("WHERE DO YOU WANT TO SEARCH : " + "\n0- C: \n1-D:\n2-E:\n3-F:\n4-G:\n5-H:\n6-I:\n7-ALL" );
driveIndex = scan.nextInt();
}
public void fileSearch()
{
if(driveIndex!=7)
{
f1= new File(drives[driveIndex]);
files = f1.list();
try
{
do
{
for(i=0; files[i]!=""; i++)
{
if(fileName.equalsIgnoreCase(files[i]))
{
flag++;
break;
}
for(m=0; m<files[i].length(); m++)
{
if(files[l].charAt(m)=='.')
flag2++;
}
if(flag2==0)
{
f3= new File(drives[driveIndex]+files[i]);
files = f3.list();
}
}
}while()
}catch(Exception e){}
}
if(driveIndex==7)
{
for(k=0; k<=6; k++)
{
f2 = new File(drives[k]);
files = f2.list();
try
{
for(j=0; files[j]!=""; j++)
{
if(fileName.equalsIgnoreCase(files[j]))
{
flag++;
break;
}
}
}catch(Exception e) { continue;}
if(flag==1)
break;
}
}
}
//yet to search the folders inside the drives..
public void display()
{
try{if(flag==0)
System.out.println("FILE NOT FOUND ");
else
System.out.println("FILE FOUND "+ "\nIN "+ drives[k] );
}catch(Exception e) {}
}
public static void main(String args [])
{
SearchMachine s= new SearchMachine();
s.getFileName();
s.getLocation();
s.fileSearch();
s.display();
}
}