Name
rmdir - Removes a directory.
Syntax
#include <direct.h>
int rmdir(path)
char *path;
Description
The rmdir function deletes the directory specified by path.
The directory must be empty, and it must not be the current
working directory or the root directory.
Return Value
The rmdir function 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 Meaning
EACCES The given path name is not a directory;
or the directory is not empty; or the
directory is the current working
directory or the root directory.
ENOENT Path name not found.
See Also
chdir(DOS), mkdir(DOS)
Example
#include <direct.h> #include <stdio.h>
main()
{
int result1, result2;
/* Remove "\sub1" from root directory: */
result1 = rmdir("\\sub1");
if (result1 == -1)
perror("Unable to remove directory");
else
printf("Directory successfully removed\n");
/* Remove subdirectory "sub2" from */
/* the current working directory: */
result2 = rmdir("sub2");
if (result2 == -1)
perror("Unable to remove directory");
else
printf("Directory successfully removed\n");
}
This program uses rmdir to remove the subdirectory sub1 from
the root directory and the subdirectory sub2 from the
current working directory.
(printed 6/18/89)