delete an empty directory
#include <sys/types.h> #include <unistd.h> int rmdir( const char *path );
The rmdir() function removes (deletes) the specified directory. The directory must not contain any files or directories. The path can be either relative to the current working directory, or it can be an absolute path name.
You can't use rmdir() to delete the root directory. |
If the directory's link count becomes zero and no process has the directory open, the space occupied by the directory is freed, and the directory is no longer accessible. If one or more processes have the directory open when the last link is removed, the dot and dot-dot entries, if present, are removed before rmdir() returns, and no new entries may be created in the directory, but the directory isn't removed until all references to it have been closed.
Upon successful completion, the rmdir() function will mark for update the st_ctime and st_mtime fields of the parent directory.
To remove the directory called /home/terry
#include <sys/types.h> #include <sys/stat.h> int main( void ) { rmdir( "/home/terry" ); return (EXIT_SUCCESS); }
POSIX 1003.1
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
chdir(), chmod(), errno, getcwd(), mkdir(), stat(), umask()