std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories (3) - Linux Manuals
std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories: std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories
Command to display std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories
manual in Linux: $ man 3 std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories
NAME
std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories - std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories
Synopsis
Defined in header <experimental/filesystem>
bool create_directory( const path& p ); (1) (filesystem TS)
bool create_directory( const path& p, error_code& ec );
bool create_directory( const path& p, const path& existing_p ); (2) (filesystem TS)
bool create_directory( const path& p, const path& existing_p, error_code& ec );
bool create_directories( const path& p ); (3) (filesystem TS)
bool create_directories( const path& p, error_code& ec );
1) Creates the directory p as if by POSIX mkdir() with a second argument of static_cast<int>(fs::perms::all) (the parent directory must already exist). If p already exists and is already a directory, the function does nothing (this condition is not treated as an error).
2) Same as (1), except that the attributes of the new directory are copied from existing_p (which must be a directory that exists). It is OS-dependent which attributes are copied: on POSIX systems, the attributes are copied as if by
stat(existing_p.c_str(), &attributes_stat)
mkdir(p.c_str(), attributes_stat.st_mode)
On Windows OS, the attributes are copied as if by
CreateDirectoryExW(existing_p.c_str(), p.c_str(), 0)
3) Executes (1) for every element of p that does not already exist.
The non-throwing overloads return false if any error occurs.
Parameters
p - the path to the new directory to create
existing_p - the path to a directory to copy the attributes from
ec - out-parameter for error reporting in the non-throwing overload
Return value
1,2) true if directory creation is successful, false otherwise.
Exceptions
1,3) The overload that does not take a error_code& parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument and the OS error code as the error code argument. std::bad_alloc may be thrown if memory allocation fails. The overload taking a error_code& parameter sets it to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur. This overload has
noexcept specification:
noexcept
2) The overload that does not take a error_code& parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument, existing_p as the second argument, and the OS error code as the error code argument. std::bad_alloc may be thrown if memory allocation fails. The overload taking a error_code& parameter sets it to the OS API error code if an OS API call fails, and executes ec.clear() if no errors occur. This overload has
noexcept specification:
noexcept
Notes
The attribute-preserving overload (2) is implicitly invoked by copy() when recursively copying directories. Its equivalent in boost.filesystem is copy_directory (with argument order reversed)
Example
// Run this code
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main()
{
fs::create_directories("sandbox/1/2/a");
fs::create_directory("sandbox/1/2/b");
fs::permissions("sandbox/1/2/b", fs::perms::remove_perms | fs::perms::others_all);
fs::create_directory("sandbox/1/2/c", "sandbox/1/2/b");
std::system("ls -l sandbox/1/2");
fs::remove_all("sandbox");
}
Possible output:
drwxr-xr-x 2 user group 4096 Apr 15 09:33 a
drwxr-x--- 2 user group 4096 Apr 15 09:33 b
drwxr-x--- 2 user group 4096 Apr 15 09:33 c
See also
creates a symbolic link
create_symlink (function)
create_directory_symlink
copies files or directories
copy (function)
identifies file system permissions
perms (enum)
Pages related to std::experimental::filesystem::create_directory,std::experimental::filesystem::create_directories
- std::experimental::filesystem::create_directory, (3) - std::experimental::filesystem::create_directory,
- std::experimental::filesystem::create_hard_link (3) - std::experimental::filesystem::create_hard_link
- std::experimental::filesystem::create_symlink, (3) - std::experimental::filesystem::create_symlink,
- std::experimental::filesystem::create_symlink,std::experimental::filesystem::create_directory_symlink (3) - std::experimental::filesystem::create_symlink,std::experimental::filesystem::create_directory_symlink
- std::experimental::filesystem::canonical (3) - std::experimental::filesystem::canonical
- std::experimental::filesystem::copy (3) - std::experimental::filesystem::copy
- std::experimental::filesystem::copy_file (3) - std::experimental::filesystem::copy_file
- std::experimental::filesystem::copy_options (3) - std::experimental::filesystem::copy_options
- std::experimental::filesystem::copy_symlink (3) - std::experimental::filesystem::copy_symlink
- std::experimental::filesystem::current_path (3) - std::experimental::filesystem::current_path
- std::experimental::filesystem::absolute,std::experimental::filesystem::system_complete (3) - std::experimental::filesystem::absolute,std::experimental::filesystem::system_complete
- std::experimental::filesystem::begin(directory_iterator), (3) - std::experimental::filesystem::begin(directory_iterator),
- std::experimental::filesystem::begin(directory_iterator),std::experimental::filesystem::end(directory_iterator) (3) - std::experimental::filesystem::begin(directory_iterator),std::experimental::filesystem::end(directory_iterator)
- std::experimental::filesystem::begin(recursive_directory_iterator), (3) - std::experimental::filesystem::begin(recursive_directory_iterator),
- std::experimental::filesystem::begin(recursive_directory_iterator),std::experimental::filesystem::end(recursive_directory_iterator) (3) - std::experimental::filesystem::begin(recursive_directory_iterator),std::experimental::filesystem::end(recursive_directory_iterator)
- std::experimental::filesystem::directory_entry (3) - std::experimental::filesystem::directory_entry
- std::experimental::filesystem::directory_entry::assign (3) - std::experimental::filesystem::directory_entry::assign
- std::experimental::filesystem::directory_entry::directory_entry (3) - std::experimental::filesystem::directory_entry::directory_entry
- std::experimental::filesystem::directory_entry::operator= (3) - std::experimental::filesystem::directory_entry::operator=
- std::experimental::filesystem::directory_entry::operator==,!=,<,<=,>,>= (3) - std::experimental::filesystem::directory_entry::operator==,!=,<,<=,>,>=
- std::experimental::filesystem::directory_entry::path (3) - std::experimental::filesystem::directory_entry::path
- std::experimental::filesystem::directory_entry::replace_filename (3) - std::experimental::filesystem::directory_entry::replace_filename
- std::experimental::filesystem::directory_entry::status, (3) - std::experimental::filesystem::directory_entry::status,
- std::experimental::filesystem::directory_entry::status,std::experimental::filesystem::directory_entry::symlink_status (3) - std::experimental::filesystem::directory_entry::status,std::experimental::filesystem::directory_entry::symlink_status
- std::experimental::filesystem::directory_iterator (3) - std::experimental::filesystem::directory_iterator
- std::experimental::filesystem::directory_iterator::directory_iterator (3) - std::experimental::filesystem::directory_iterator::directory_iterator
- std::experimental::filesystem::directory_iterator::operator*,operator-> (3) - std::experimental::filesystem::directory_iterator::operator*,operator->
- std::experimental::filesystem::directory_iterator::operator= (3) - std::experimental::filesystem::directory_iterator::operator=
- std::experimental::filesystem::directory_options (3) - std::experimental::filesystem::directory_options
- std::experimental::filesystem::equivalent (3) - std::experimental::filesystem::equivalent
- std::experimental::filesystem::exists (3) - std::experimental::filesystem::exists
- std::experimental::filesystem::file_size (3) - std::experimental::filesystem::file_size
- std::experimental::filesystem::file_status (3) - std::experimental::filesystem::file_status
- std::experimental::filesystem::file_status::file_status (3) - std::experimental::filesystem::file_status::file_status
- std::experimental::filesystem::file_status::operator= (3) - std::experimental::filesystem::file_status::operator=