-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.cpp
More file actions
35 lines (29 loc) · 842 Bytes
/
search.cpp
File metadata and controls
35 lines (29 loc) · 842 Bytes
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
#include "headers.h"
string search(string file_name, string dir){
struct dirent *myfile;
DIR *mydir;
int flag=0;
mydir=opendir(dir.c_str());
if (mydir == NULL){
perror("Error opening directory");
return "False";
}
while ((myfile = readdir(mydir)) != NULL){
if(strcmp(myfile->d_name, ".") == 0 || strcmp(myfile->d_name, "..") == 0){
continue;
}
string dir_path = dir + "/" + myfile->d_name;
if(myfile->d_type == DT_DIR){ // Check if it's a directory
if(search(file_name , dir_path) == "True") {
closedir(mydir);
return "True";
}
}
else if(myfile->d_name == file_name){
flag = 1;
return "True";
}
}
if(flag == 0)
return "False";
}