Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <fcntl.h>
- #include <string.h>
- #include <dirent.h>
- #define BUFF_SIZE 1024
- void browseDir(char *dirname, char* searchStr){
- DIR* dd;
- struct dirent * de;
- char newDirName[1024];
- if(!(dd = opendir(dirname))){
- printf("Error reading dir: %s\n", dirname);
- return;
- }
- while(de = readdir(dd)){
- if(de->d_type == DT_DIR){
- if(!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) continue;
- strcpy(newDirName, dirname);
- strcpy(newDirName+strlen(newDirName), de->d_name);
- strcpy(newDirName+strlen(newDirName), "/");
- browseDir(newDirName, searchStr);
- }else{
- if(!strcmp(de->d_name, searchStr)){
- printf("Found at: %s%s\n", dirname, de->d_name);
- }
- }
- //printf("Entryname: %s, Type: %d\n", de->d_name, de->d_type);
- }
- }
- int main(int argc, char *argv[]){
- char dirname[1024] = "/home/";
- browseDir(dirname, argv[1]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement