std::experi..._directory,(3)
πΈ NAME πΈ β std::experi..._directory,(3) from the C++ Standard Libary
okay so bestie, you opened the std::experi..._directory,(3) page in the C++ Standard Libary, and the NAME section is exactly this icon:
std::experimental::filesystem::create_directory, - std::experimental::filesystem::create_directory,
Thatβs the whole name vibe as printed β yes, with the comma and the dash doing their little thing. Weβre also covering create_directories because it shows up in the synopsis and itβs part of this whole directory-making moment. π«Ά
π SYNOPSIS π
First, the signatures, with the (filesystem TS) labels and overload numbers kept exactly where they were:
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 );
bool create_directory( const path& p, const path& existing_p, (2)
(filesystem TS)
error_code& ec );
bool create_directories( const path& p ); (3)
(filesystem TS)
bool create_directories( const path& p, error_code& ec );
Then the actual tea:
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 createexisting_pβ the path to a directory to copy the attributes fromecβ 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 an 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 an 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 an 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 an 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 <cstdlib>
#include <experimental/filesystem>
#include <fstream>
#include <iostream>
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 π
create_symlinkβ creates a symbolic linkcreate_directory_symlinkβ(function)copyβ copies files or directories(function)permsβ identifies file system permissions(enum)
π·οΈ CATEGORIES π·οΈ
- Noindexed pages
- unconditionally noexcept
π HIDDEN CATEGORIES π
- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template
And thatβs the vibe check, bestie: this page came from http://cppreference.com, dated 2024.06.10, and the footer name is std::experi..._directory,(3). Slay the filesystem responsibly! πβ¨π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms