Course Content
Programming in C
About Lesson

We can create a directory using mkdir system call and remove one using rmdir system call.

#include <sys/stat.h>

int mkdir(const char *pathname, mode_t mode);

mkdir creates a new, empty directory (with entries for . and ..) with directory name passed as the first argument. Mode parameter can be used to specify access permissions. Note that execute permission is required to access filenames within the directory, hence we would normally want to at least set at least one of the execute bits.

An empty directory (containing only . and ..) can be deleted using rmdir.

#include <unistd.h>

int rmdir(const char *pathname);

rmdir returns 0 on success and -1 on failure.

Scroll to Top