[fs.op.create.directory]

# 31 Input/output library [[input.output]](./#input.output)

## 31.12 File systems [[filesystems]](filesystems#fs.op.create.directory)

### 31.12.13 Filesystem operation functions [[fs.op.funcs]](fs.op.funcs#fs.op.create.directory)

#### 31.12.13.8 Create directory [fs.op.create.directory]

[ð](#lib:create_directory)

`bool filesystem::create_directory(const path& p);
bool filesystem::create_directory(const path& p, error_code& ec) noexcept;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17574)

*Effects*: Creates the directory p resolves to,
 as if by POSIX mkdir with a second argument of static_cast<int>(perms​::​all)[.](#1.sentence-1)

If mkdir fails because p resolves to an existing directory,
 no error is reported[.](#1.sentence-2)

Otherwise on failure an error is reported[.](#1.sentence-3)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17582)

*Returns*: true if a new directory was created, otherwise false[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17586)

*Throws*: As specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting")[.](#3.sentence-1)

[ð](#lib:create_directory_)

`bool filesystem::create_directory(const path& p, const path& existing_p);
bool filesystem::create_directory(const path& p, const path& existing_p, error_code& ec) noexcept;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17598)

*Effects*: Creates the
 directory p resolves to, with
 attributes copied from directory existing_p[.](#4.sentence-1)

The set of attributes
 copied is operating system dependent[.](#4.sentence-2)

If mkdir fails because p resolves to an existing directory,
 no error is reported[.](#4.sentence-3)

Otherwise on failure an error is reported[.](#4.sentence-4)

[*Note [1](#note-1)*:

For POSIX-based operating systems, the
 attributes are those copied by native API stat(existing_p.c_str(), &attributes_stat) followed by mkdir(p.c_str(), attributes_stat.st_mode)[.](#4.sentence-5)

For
 Windows-based operating systems, the attributes are those copied by native
 API CreateDirectoryExW(existing_p.c_str(), p.c_str(), 0)[.](#4.sentence-6)

â *end note*]

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17614)

*Returns*: true if a new directory was created
 with attributes copied from directory existing_p,
 otherwise false[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iostreams.tex#L17620)

*Throws*: As specified in [[fs.err.report]](fs.err.report "31.12.5 Error reporting")[.](#6.sentence-1)
