Example (rmdir -- Remove Directory)

This example deletes two directories: one in the root directory, and the other in the current working directory.

#include <stdio.h>
#include <direct.h>
#include <string.h>
int main(void)
{
   char *dir1,*dir2;
 /*  Create the directory "aleng" in the root directory of the C: drive.      */
   dir1 = "c:\\aleng";
   if (0 == (mkdir(dir1)))
      printf("%s directory was created.\n", dir1);
   else
      printf("%s directory was not created.\n", dir1);
 /*  Create the subdirectory "simon" in the current directory.                */
   dir2 = "simon";
   if (0 == (mkdir(dir2)))
      printf("%s directory was created.\n", dir2);
   else
      printf("%s directory was not created.\n", dir2);
 /*  Remove the directory "aleng" from the root directory of the C: drive.    */
   printf("Removing directory 'aleng' from the root directory.\n");
   if (rmdir(dir1))
      perror(NULL);
   else
      printf("%s directory was removed.\n", dir1);
 /*  Remove the subdirectory "simon" from the current directory.              */
   printf("Removing subdirectory 'simon' from the current directory.\n");
   if (rmdir(dir2))
      perror(NULL);
   else
      printf("%s directory was removed.\n", dir2);
   return 0;
   /****************************************************************************
      The output should be:
      c:\aleng directory was created.
      simon directory was created.
      Removing directory 'aleng' from the root directory.
      c:\aleng directory was removed.
      Removing subdirectory 'simon' from the current directory.
      simon directory was removed.
   ****************************************************************************/
}