How to create a directory with C code (other than the method of forking and using mkdir) ? Is there anything like dirent.h? dirent.h only allows to read directories. (withou
Use the mkdir function.
#include <sys/stat.h>
#include <sys/types.h>
int mkdir(const char *pathname, mode_t mode);
With the advent of c++17
we have a Filesystem library providing facilities for manipulating files and directory. To create a directory, you can use std::filesystem::create_directory.
Example:
#include <filesystem>
std::filesystem::create_directory("newdir");
If you can use C++ (as suggested by the selected tags) and boost libraries, Boost filesystem can help you with the create_directory function.
If you don't want to have all boost libraries available in your project, you may download a tool called bcp to extract only the subset you need, in your case boost filesystem and its dependencies.
Call mkdir(2).