Syntax
#include <direct.h> int rmdir(char *pathname);Description
rmdir deletes the directory specified by pathname. The directory must be empty, and it must not be the current working directory or the root directory.
Note: In earlier releases of C Set ++, rmdir began with an underscore (_rmdir). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, The Developer's Toolkit will map _rmdir to rmdir for you.
rmdir returns the value 0 if the directory is successfully deleted. A return value of -1 indicates an error, and errno is set to one of the following values:
Value
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.
****************************************************************************/
}
Related Information