title: Recursively remove a directory using C
body: <p>I want to implement this myself and I come up something like this:</p>
  
  <pre><code>/* DIR *opendir(const char *name);
   *
   * Open a directory stream to argv[1] and make sure
   * it's a readable and valid (directory) */
  if ((dip = opendir(argv[1])) == NULL)
  {
          perror("opendir");
          return 0;
  }
  
  printf("Directory stream is now open\n");
  
  /*  struct dirent *readdir(DIR *dir);
   *
   * Read in the files from argv[1] and print */
  while ((dit = readdir(dip)) != NULL)
  {
          printf("\n%s", dit-&gt;d_name);
          remove(dit-&gt;d_name);
  }
  </code></pre>
  
  <p>I am guessing I have to start delete things from the deepest level and then go up, but now it seems readdir does not give me that order.</p>
  
  <p>Please help, thanks!</p>