Seemingly random opendir() failure C -


so i've written short c program explores files on computer file. wrote simple function takes directory, opens looks around:

int exploredir (char stringdir[], char search[]) {         dir* dir;     struct dirent* ent;         if ((dir = opendir(stringdir)) == null)     {          printf("error: not open directory %s\n", stringdir);          return 0;                  }      while ((ent = readdir(dir)) != null)     {         if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)              continue;          if (strlen(stringdir) + 1 + strlen(ent->d_name) > 1024)         {             perror("\nerror: file path long!\n");             continue;         }               char filepath[1024];         strcpy(filepath, stringdir);         strcat(filepath, "/");         strcat(filepath, ent->d_name);          if (strcmp(ent->d_name, search) == 0)         {             printf(" found it! it's at: %s\n", filepath);             return 1;         }          struct stat st;          if (lstat(filepath, &st) < 0)         {             perror("error: lstat() failure");             continue;          }          if (st.st_mode & s_ifdir)         {              dir* tempdir;              if ((tempdir = opendir (filepath)))              {                  exploredir(filepath, search);                             }           }      }     closedir(dir);     return 0;  } 

however, keep getting output:

error: not open directory /users/dan/desktop/box/videos error: not open directory /users/dan/desktop/compilerhome 

the problem is, have no idea these files cause opendir() fail. don't have them open in program. they're simple folders created on desktop. have idea problem be?

you calling opendir() twice each closedir(). maybe running out of resources.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -