GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::filesystem::create_directory,std::filesystem::create_directories(3) C++ Standard Libary std::filesystem::create_directory,std::filesystem::create_directories(3)

std::filesystem::create_directory,std::filesystem::create_directories - std::filesystem::create_directory,std::filesystem::create_directories


Defined in header <filesystem>
bool create_directory( const std::filesystem::path& p );
bool create_directory( const std::filesystem::path& p, (1) (since C++17)
std::error_code& ec ) noexcept;
bool create_directory( const std::filesystem::path& p,


const std::filesystem::path& existing_p );
bool create_directory( const std::filesystem::path& p, (2) (since C++17)
const std::filesystem::path& existing_p,


std::error_code& ec ) noexcept;
bool create_directories( const std::filesystem::path& p );
bool create_directories( const std::filesystem::path& p, (3) (since C++17)
std::error_code& ec );


1) Creates the directory p as if by POSIX mkdir() with a second argument of
static_cast<int>(std::filesystem::perms::all) (the parent directory must already
exist). If the function fails because p resolves to an existing directory, no error
is reported. Otherwise on failure an error is reported.
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, no attributes of existing_p are copied.
3) Executes (1) for every element of p that does not already exist. If p already
exists, the function does nothing (this condition is not treated as an error).


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


true if a directory was created for the directory p resolves to, false otherwise.


1,3) The overload that does not take a std::error_code& parameter throws
filesystem::filesystem_error on underlying OS API errors, constructed with p as the
first path argument and the OS error code as the error code argument. The overload
taking a std::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. Any overload not marked
noexcept may throw std::bad_alloc if memory allocation fails.
2) The overload that does not take a std::error_code& parameter throws
filesystem::filesystem_error on underlying OS API errors, constructed with p as the
first path argument, existing_p as the second path argument, and the OS error code
as the error code argument. The overload taking a std::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. Any overload not marked noexcept may throw std::bad_alloc if memory
allocation fails.


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)

// Run this code


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <filesystem>
namespace fs = std::filesystem;


int main()
{
fs::current_path(fs::temp_directory_path());
fs::create_directories("sandbox/1/2/a");
fs::create_directory("sandbox/1/2/b");
fs::permissions("sandbox/1/2/b", fs::perms::others_all, fs::perm_options::remove);
fs::create_directory("sandbox/1/2/c", "sandbox/1/2/b");
std::system("ls -l sandbox/1/2");
std::system("tree sandbox");
fs::remove_all("sandbox");
}


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
sandbox
└── 1
└── 2
├── a
├── b
└── c


Defect reports


The following behavior-changing defect reports were applied retroactively to
previously published C++ standards.


DR Applied to Behavior as published Correct behavior
LWG 2935 C++17 error if target already exists but isn't a not error
directory
LWG 3014 C++17 error_code overload of create_directories noexcept removed
marked noexcept but can allocate memory
P1164R1 C++17 creation failure caused by an existing made error
non-directory file is not an error


create_symlink
create_directory_symlink creates a symbolic link
(C++17) (function)
(C++17)
copy copies files or directories
(C++17) (function)
perms identifies file system permissions
(C++17) (enum)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.