title: How to check if a file exists in a folder C
body: <p>I am a C beginner and I am a bit confused about how to do this. I am trying with <code>readdir</code> and <code>strcmp</code> functions but it throws me a lot of errors.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;string.h&gt;
  #include &lt;dirent.h&gt;
  
  int main(int argc, char *argv[])
  {   
      DIR *dirp;
      struct dirent *direntp;
  
      dirp = opendir(argv[1]);
      if (dirp == NULL)
      {
          printf("File could not be open\n");
  
          return -1;
      }
  
      int i = 0;
      while((direntp[i]=readdir(dirp)) != NULL)
      {
          if(strcmp(direntp[i], argv[2]) == 0)
          {
              printf("The file %d is in directory %s my friend!", argv[2], dirp);
          }
  
          i++;
      }
  
      closedir(dirp);
      return 0;
  }
  </code></pre>