title: Unlink Not Removing File
body: <p>Trying to understand why unlink isn't working (not removing the file) in my code down below. The only thing I can imagine is that the program thinks I'm still interacting with the file so its not actually unlinking it since its still in use. The code is meant to be a copy of "rm"</p>
  
  <pre><code>void directorySearch(const char *dName)
  {
          DIR *dir;
          struct dirent *ent;
          if ((dir = opendir (dName)) != NULL)
          {
                  while ((ent = readdir (dir)) != NULL)
                  {
  
                          if ( ent-&gt;d_type!=DT_DIR)
                          {
                                  //Where the crazy happens
                                  printf ("%s\n", ent-&gt;d_name);
                                  char path[PATH_MAX];
                                  const char * d_name = ent-&gt;d_name;
                                  unlink(path);
                          }
                          if ( ent-&gt;d_type==DT_DIR &amp;&amp; strcmp(ent-&gt;d_name, ".")!= 0 &amp;&amp; strcmp(ent-&gt;d_name, "..") != 0)
                          {
                                  int path_length;
                                  char path[PATH_MAX];
                                  const char * d_name = ent-&gt;d_name;
  
                                  path_length = snprintf (path, PATH_MAX, "%s/%s", dName, d_name);
  
                                  directorySearch(path);
                          }
                  }
                  closedir (dir);
          }
          else
          {
                  cout &lt;&lt; "error with "&lt;&lt; dName&lt;&lt; endl;
          }
  }
  </code></pre>
  
  <p>Edited with unlink instead of remove, although both don't work...</p>