Creating a directory In C or C++

前端 未结 4 1454
悲&欢浪女
悲&欢浪女 2021-01-18 11:44

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

相关标签:
4条回答
  • 2021-01-18 12:04

    Use the mkdir function.

    #include <sys/stat.h>
    #include <sys/types.h>
    int mkdir(const char *pathname, mode_t mode);
    
    0 讨论(0)
  • 2021-01-18 12:05

    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");
    
    0 讨论(0)
  • 2021-01-18 12:07

    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.

    0 讨论(0)
  • 2021-01-18 12:21

    Call mkdir(2).

    0 讨论(0)
提交回复
热议问题