2 <!-- © Copyright Beman Dawes, 2002, 2006, 2007, 2009, 2010, 2011 -->
3 <!-- Distributed under the Boost Software License, Version 1.0. -->
4 <!-- See http://www.boost.org/LICENSE_1_0.txt -->
6 <!-- generate-section-numbers=false -->
9 <meta http-equiv="Content-Language" content="en-us">
10 <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
11 <meta name="ProgId" content="FrontPage.Editor.Document">
12 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
13 <link href="styles.css" rel="stylesheet">
14 <title>Filesystem Reference</title>
21 <table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
25 <a href="../../../index.htm">
26 <img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="300" height="86" border="0"></a></td>
28 <font size="7">Filesystem Library<br>
30 <font size="6">Version 3</font></td>
34 <table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
35 bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
37 <td><a href="index.htm">Home</a>
38 <a href="tutorial.html">Tutorial</a>
39 <a href="reference.html">Reference</a>
40 <a href="faq.htm">FAQ</a>
41 <a href="release_history.html">Releases</a>
42 <a href="portability_guide.htm">Portability</a>
43 <a href="v3.html">V3 Intro</a>
44 <a href="v3_design.html">V3 Design</a>
45 <a href="deprecated.html">Deprecated</a>
46 <a href="issue_reporting.html">Bug Reports </a>
50 <h1>Reference Documentation</h1>
54 <h2><a name="TOC">Table of Contents</a></h2>
56 <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
58 <td width="33%" valign="top">
59 <p><a href="#Introduction">Introduction</a><br>
60 <a href="#Definitions">Definitions</a><br>
61 <a href="#Conformance">Conformance</a><br>
62 <a href="#Header-filesystem-synopsis">
63 Header <code><boost/filesystem.hpp></code> synopsis</a><br>
64 <a href="#Error-reporting">Error reporting</a><br>
65 <a href="#class-path">Class <code>path</code></a><br>
66 <a href="#path-Conversions"><code>path</code> conversions</a><br>
67 <a href="#path-Conversions-to-native-format"><code>path</code>
68 conversions to native format</a><br>
69 <a href="#path-Conversions-to-generic-format"><code>path</code>
70 conversions to generic format</a><br>
71 <a href="#path-Encoding-conversions"><code>path</code>
72 encoding conversions</a><br>
73 <a href="#path-Requirements"><code>path</code> requirements</a><br>
74 <a href="#path-constructors"><code>path</code> constructors</a><br>
75 <a href="#path-assignments"><code>path</code> assignments</a><br>
76 <a href="#path-appends"><code>path</code> appends</a><br>
77 <a href="#path-concatenation"><code>path</code> concatenation</a><br>
78 <a href="#path-modifiers"><code>path</code> modifiers</a><br>
79 <a href="#path-native-format-observers"><code>path</code> native
80 format observers</a><br>
81 <a href="#path-generic-format-observers"><code>path</code> generic
82 format observers</a><br>
83 <a href="#path-compare"><code>path</code> compare</a><br>
84 <a href="#path-decomposition"><code>path</code> decomposition</a><br>
85 <a href="#path-query"><code>path</code> query</a><br>
86 <a href="#path-iterators"><code>path</code> iterators</a><br>
88 <a href="#path-deprecated-functions"><code>path</code> deprecated functions</a><br>
89 <a href="#path-non-member-functions"><code>path</code> non-member functions</a><br>
90 <a href="#path-inserter-extractor"><code>path</code> inserters and extractors</a><br>
91 <a href="#Class-filesystem_error">Class <code>filesystem_error</code></a><br>
92 <a href="#filesystem_error-members"><code>filesystem_error</code>
94 <a href="#filesystem_error-path1"><code>filesystem_error</code> path1</a><br>
95 <a href="#filesystem_error-path2"><code>filesystem_error</code> path2</a><br>
96 <a href="#filesystem_error-what"><code>filesystem_error</code> what</a></td>
97 <td width="33%" valign="top">
99 <a href="#Enum-file_type">Enum <code>file_type</code></a><br>
100 <a href="#Enum-perms">Enum <code>perms</code></a><br>
101 <a href="#file_status">Class
102 <code>file_status</code></a><br>
104 <a href="#file_status">
105 <code>file_status</code></a><a href="#file_status-constructors"> constructors</a><br>
106 <code><a href="#file_status-modifiers">file_status-modifiers</a></code><a href="#directory_entry-observers"> observers</a><br>
107 <code><a href="#file_status-observers">file_status-observers</a></code><a href="#directory_entry-modifiers"> modifiers</a><br>
108 <a href="#Class-directory_entry">Class <code>directory_entry</code></a><br>
110 <a href="#directory_entry-constructors"><code>directory_entry</code> constructors</a><br>
111 <a href="#directory_entry-observers"><code>directory_entry</code> observers</a><br>
112 <a href="#directory_entry-modifiers"><code>directory_entry</code> modifiers</a><br>
113 <a href="#Class-directory_iterator">Class <code>directory_iterator</code></a><br>
114 <a href="#directory_iterator-members"><code>directory_iterator</code>
116 <a href="#Class-recursive_directory_iterator">Class <code>recursive_directory_iterator</code></a><br>
117 <a href="#Operational-functions">
118 Operational functions</a><br>
119 <code> <a href="#absolute">absolute</a><br>
120 <a href="#canonical">canonical</a><br>
121 <a href="#copy">copy</a><br>
122 <a href="#copy_directory">copy_directory</a><br>
123 <a href="#copy_file">copy_file</a><br>
124 <a href="#copy_symlink">copy_symlink</a><br>
125 <a href="#create_directories">create_directories</a><br>
126 <a href="#create_directory">create_directory</a><br>
127 <a href="#create_hard_link">create_hard_link</a><br>
128 <a href="#create_symlink">create_symlink</a><br>
129 <a href="#current_path">current_path</a><br>
130 <a href="#exists">exists</a><br>
131 <a href="#equivalent">equivalent</a><br>
132 <a href="#file_size">file_size</a><br>
133 <a href="#hard_link_count">hard_link_count</a><br>
134 <a href="#initial_path">initial_path</a><br>
135 i<a href="#is_directory">s_directory</a><br>
136 <a href="#is_empty">is_empty</a></code></td>
137 <td width="34%" valign="top">
139 <code> <a href="#is_other">is_other</a><br>
140 <a href="#is_regular_file">is_regular_file</a><br>
141 <a href="#is_symlink">is_symlink</a><br>
142 <a href="#last_write_time">last_write_time</a><br>
143 <a href="#permissions">permissions</a><br>
144 <a href="#read_symlink">read_symlink</a><br>
145 <a href="#op-relative">relative</a><br>
146 <a href="#remove">remove</a><br>
147 <a href="#remove_all">remove_all</a><br>
148 <a href="#rename">rename</a><br>
149 <a href="#resize_file">resize_file</a><br>
150 <a href="#space">space</a><br>
151 <a href="#status">status</a><br>
152 <a href="#status_known">status_known</a><br>
153 <a href="#symlink_status">symlink_status</a><br>
154 <a href="#system_complete">system_complete</a><br>
155 <a href="#temp_directory_path">temp_directory_path</a><br>
156 <a href="#unique_path">unique_path</a><br>
157 <a href="#weakly_canonical">weakly_canonical</a><br></code>
158 <a href="#File-streams">File streams</a><br>
159 <a href="#path-decomposition-table">Path decomposition table</a><br>
160 <a href="#long-path-warning">Warning: Long paths on Windows and the
161 extended-length <b>\\?\ </b>prefix</a><br>
162 <a href="#Acknowledgements">Acknowledgements</a><br>
163 <a href="#References">References</a><br>
169 <h2><a name="Introduction">Introduction</a></h2>
171 <p>This reference documentation describes components that C++ programs may use
172 to perform operations involving file systems, including paths, regular files,
176 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
177 bordercolor="#111111" bgcolor="#D7EEFF" width="90%">
179 <td width="100%" align="center" colspan="2">
180 <p align="center"><b>C++11 Support</b><p align="left">This reference
181 documentation is written as if all compilers supported C++11. Where
182 possible, the implementation falls back to C++03 if a C++11 feature is not
186 <td width="35%" align="center">
188 <b>C++11 Feature</b></td>
189 <td width="65%" align="center">
191 <b>Action if not supported by compiler</b></td>
194 <td width="35%" align="left">
196 <code>noexcept</code></td>
197 <td width="65%" align="left">
198 <p>Keyword omitted.</td>
201 <td width="35%" align="left">
203 <code>constexpr</code></td>
204 <td width="65%" align="left">
205 <p>Keyword omitted.</td>
208 <td width="35%" align="left">
209 <p>R-value references</td>
210 <td width="65%" align="left">
211 <p>Function signature omitted.</td>
214 <td width="35%" align="left">
215 <p>New character types</td>
216 <td width="65%" align="left">
217 <p>The <code>boost::filesystem</code> interface doesn't use the
218 new types directly. It does use <code>u16string</code> and <code>u32string</code>
219 in namespace <code>boost</code>. These are typedefs to <code>std::u16string</code>
220 and <code>std::u32string</code> for C++11, or to <code>
221 std::basic_string<boost::u16_t></code> and <code>
222 std::basic_string<boost::u32_t></code> for C++03.</td>
225 <td width="35%" align="left">
226 <p>Defaulted and deleted functions</td>
227 <td width="65%" align="left">
228 <p>Workaround replacement functions provided.</td>
231 <td width="35%" align="left">
232 <p>Initializer lists</td>
233 <td width="65%" align="left">
234 <p>Not currently used.</td>
237 <td width="35%" align="left">
238 <p>Variadic templates</td>
239 <td width="65%" align="left">
240 <p>Not currently used.</td>
243 <td width="35%" align="left">
244 <p>Range-based for statements</td>
245 <td width="65%" align="left">
246 <p>Supporting functions always provided; they do no harm even for C++03
254 <h2><a name="Conformance">Conformance</a> [fs.conformance]</h2>
256 <h3>ISO/IEC 9945 conformance [fs.conform.9945]</h3>
257 <p>Some behavior in this reference documentation is specified by reference to ISO/IEC 9945. How such behavior is actually implemented is unspecified.</p>
259 <p>[<i>Note:</i> This constitutes an "as if" rule for implementation of
260 operating system dependent behavior. In practice implementations will usually call native
261 operating system API's. <i>—end note</i>]</p>
263 <p>Implementations are encouraged to provide such behavior
265 as it is defined by ISO/IEC 9945. Implementations shall document any
266 behavior that differs from the behavior defined by ISO/IEC 9945. Implementations that do not support exact
267 ISO/IEC 9945 behavior are
268 encouraged to provide behavior as close to ISO/IEC 9945 behavior as is reasonable given the
269 limitations of actual operating systems and file systems. If an implementation cannot provide any
270 reasonable behavior, the implementation shall report an error in an
271 implementation-defined manner.</p>
273 <p>[<i>Note:</i> Such errors might be reported by an #error directive, a <code>
274 static_assert</code>, a <code>filesystem_error</code> exception, a special
275 return value, or some other manner. <i>—end note</i>]</p>
277 <p>Implementations are not required to provide behavior that is not supported by
278 a particular file system.</p>
280 <p>[<i>Example:</i> The <a href="http://en.wikipedia.org/wiki/FAT_filesystem">
281 FAT file system</a> used by some memory cards, camera memory, and floppy discs
282 does not support hard links, symlinks, and many other features of more capable
283 file systems. Implementations are only required to support the FAT features
284 supported by the host operating system. <i>—end example</i>]</p>
286 <p>The behavior of functions described in this
288 may differ from their specification in
289 the presence of <a href="#file-system-race">file system races</a>. No diagnostic is required.</p>
290 <p>If the possibility of a file system race would make it unreliable for a program to
291 test for a precondition before calling a function described in this reference documentation, <i>
292 Requires</i> is not specified for the condition. Instead, the condition is
293 specified as a <i>Throws</i> condition.</p>
295 <p>[<i>Note:</i> As a design practice, preconditions are not specified when it
296 is unreasonable for a program to detect them prior to calling the function. <i>
299 <h3>Operating system dependent conformance [fs.conform.os]</h3>
300 <p>Some behavior is specified in this reference documentation as being
301 operating system dependent ([fs.def.osdep]). The operation system an
302 implementation is dependent upon is implementation defined.</p>
303 <p>It is permissible for an implementation to be dependent upon an operating
304 system emulator rather than the actual operating system.</p>
306 <p>[<i>Example:</i> An implementation uses Cygwin, a Linux® API emulator for
307 some Windows® operating system versions. The implementation would define Cygwin
308 as its operating system. Users could refer to the Cygwin documentation to find
309 details of the operating system dependent behavior. <i>—end example</i>]</p>
310 <p><span style="background-color: #E0E0E0"><i>It is user and conformance test
311 detectable that such an implementation is running on Cygwin. Users would be
312 misled and conformance tests would fail if the implementation defined Linux or
313 Windows rather than Cygwin as the operating system, since real behavior is a
314 blend of the two.</i></span> </p>
316 <h2><a name="Definitions">Definitions</a> [fs.definitions]</h2>
317 <p>The following definitions shall apply throughout this reference documentation:</p>
318 <h3><a name="operating system dependent">operating system dependent</a> behavior
320 <p>Behavior that is dependent upon the behavior
321 and characteristics of an operating system. See [fs.conform.os].</p>
322 <h3><a name="file">file</a> [fs.def.file]</h3>
323 <p>An object that can be written to, or read from, or both. A file
324 has certain attributes, including type. File types include regular files
325 and directories. Other types of files, such as symbolic links, may be supported by the
327 <h3><a name="file-system">file system</a> [fs.def.filesystem]</h3>
328 <p>A collection of files and certain of their attributes.</p>
329 <h3><a name="filename">filename</a> [fs.def.filename]</h3>
330 <p>The name of a file. Filenames <code>
331 "."</code>
332 and <code>".."</code> have special meaning. The follow characteristics of
333 filenames are operating system dependent:</p>
336 <p>The permitted characters. See [<a href="#Operating-system-examples">fs.os.examples</a>].</p>
339 <p>Specific filenames that are not permitted.</p>
342 <p>Additional filenames that have special meaning.</p>
345 <p>Case awareness and sensitivity during path resolution.</p>
348 <p>Special rules that may apply to file types other than regular
349 files, such as directories.</p>
352 <h3><a name="path">path</a> [fs.def.path]</h3>
353 <p>A sequence of elements that identify
354 the location of a file within a filesystem. The elements are the <i>root-name<sub>opt</sub></i>, <i>
355 root-directory<sub>opt</sub></i>, and an optional sequence of filenames. [<i>Note:</i>
356 A <a href="#pathname">pathname</a> is the concrete representation of a path. <i>—end note</i>]</p>
358 <h3><a name="Absolute-path">absolute path</a> [fs.def.absolute-path]</h3>
361 identifies the location of a file without reference to an additional starting
362 location. The elements of a path that determine if it is absolute are
363 operating system dependent.</p>
365 <h3><a name="Relative-path">relative path</a> [fs.def.relative-path]</h3>
367 is not absolute, and so only
369 identifies the location of a file when resolved relative to
370 an implied starting location. The elements of a path that determine if it is
371 relative are operating system dependent. [<i>Note:</i>
372 Paths <code>"."</code> and <code>".."</code> are relative paths. <i>—end note</i>]</p>
373 <h3><a name="canonical-path">canonical path</a> [fs.def.canonical-path]</h3>
374 <p>An absolute path that has
375 no elements that are symbolic links, and no <code>"."</code> or <code>".."</code> elements.</p>
376 <h3><a name="pathname">pathname</a> [fs.def.pathname]</h3>
377 <p>A character string that represents
379 path. Pathnames are formatted according to the generic pathname grammar or an
380 operating system dependent
381 native pathname format.</p>
383 <h3><a name="native-pathname-format">native pathname format</a> [fs.def.native]</h3>
384 <p>The operating system dependent pathname format accepted by the host operating system.</p>
385 <h3><a name="normal-form">normal form</a> path [fs.def.normal]</h3>
386 <p>A path with no redundant current directory (<i>dot</i>) or parent directory (<i>dot-dot</i>)
387 elements. The normal form for an empty path is an empty path. The normal form
388 for a path ending in a <i>directory-separator</i> that is not the root directory
389 is the same path with a current directory (<i>dot</i>) element appended.</p>
390 <h3><a name="link">link</a> [fs.def.link]</h3>
391 <p>A directory entry object that associates a
392 filename with a file. On some file systems, several directory entries can
393 associate names with the same file.</p>
394 <h3><a name="hard-link">hard link</a> [fs.def.hardlink]</h3>
395 <p>A link to an existing file. Some
396 file systems support multiple hard links to a file. If the last hard link to a
397 file is removed, the file itself is removed.</p>
399 <p>[<i>Note:</i> A hard link can be thought of as a shared-ownership smart
400 pointer to a file.<i> —end note</i>]<i> </i></p>
402 <h3><a name="symbolic-link">symbolic link</a> [fs.def.symlink]</h3>
403 <p>A type of file with the
404 property that when the file is encountered during pathname resolution, a string
405 stored by the file is used to modify the pathname resolution.</p>
407 <p>[<i>Note:</i> A symbolic link can be thought of as a raw pointer to a file.
408 If the file pointed to does not exist, the symbolic link is said to be a
409 "dangling" symbolic link.<i> —end note</i>]<i> </i></p>
411 <h3><a name="file-system-race">file system race</a> [fs.def.race]</h3>
412 <p>The condition that occurs
413 when multiple threads, processes, or computers interleave access and
415 the same object within a file system.</p>
416 <h2><a name="generic-pathname-format">Generic pathname format</a> [path.generic]</h2>
418 root-name<sub>opt</sub>
419 root-directory<sub>opt</sub> relative-path<sub>opt</sub></i></p>
421 </i>An
422 operating system dependent name that identifies the starting location for
426 <p>[<i>Note:</i> Many operating systems define a name
427 beginning with two <i>directory-separator</i> characters as a <i>root-name</i>
428 that identifies network or other resource locations. Some operating systems define a single letter followed by a colon as a drive
429 specifier - a <i>root-name</i> identifying a specific device such as a disc drive. <i>—end note</i>]</p>
432 <p><i>root-directory:<br>
433
434 directory-separator</i></p>
435 <p><i>relative-path:<br>
436
438 relative-path
439 directory-separator<br>
440 relative-path
441 directory-separator filename</i></p>
443 name<br>
444 </i><code>"."</code><i><br>
445 </i><code>
446 ".."</code></p>
447 <p><i>preferred-separator:<br>
448 </i>An
449 operating system dependent directory separator character. May be a synonym for <i> <code>"/"</code>.</i></p>
450 <p><i>directory-separator:<br>
451 <code>"/"<br>
452 "/"</code> directory-separator<br>
453
454 preferred-separator<br>
455
456 preferred-separator directory-separator</i></p>
457 <p>Multiple successive <i>directory-separator</i> characters are considered to
458 be the same as one <i>directory-separator</i> character.</p>
459 <p>The <i>filename</i>
460 <code>"."</code> is considered to be a reference to the current directory. The
461 <i>filename</i> <code>".."</code> is considered to be a reference to the
463 directory. Specific <i>filenames</i> may have special meanings for a particular
464 operating system.</p>
465 <h2><a name="Operating-system-examples">Operating system dependent examples</a> (Informative) [fs.os.examples]</h2>
466 <p>Certain features are specified in this reference documentation as being operating system dependent. The following table shows the application of those
467 specifications for operating systems that use the ISO/IEC 9945 or Windows® application program interfaces
468 (APIs).<sup>[footnote1]</sup></p>
469 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
471 <td valign="top" align="center">
472 <p><b>Feature</b></td>
473 <td valign="top" align="center">
474 <p><b>Section</b></td>
475 <td valign="top" align="center">
476 <p><b>ISO/IEC 9945<br>
477 POSIX</b>®<b> API</b></td>
478 <td valign="top" align="center">
479 <p><b>Windows</b>®<b> API</b></td>
480 <td valign="top" align="center">
486 ::value_type</code></td>
488 <p>[<a href="#class-path">class.path</a>]</td>
490 <p><code>char</code></td>
492 <p><code>wchar_t</code></td>
498 <p><code>path::preferred<br>
499 _separator</code></td>
501 <p>[<a href="#class-path">class.path</a>]</td>
503 <p><code>'/'</code></td>
505 <p><code>L'\\'</code> (single backslash)</td>
511 <p><code>path("/")<br>
512 .is_absolute()<br>
513 path("c:/")<br>
514 .is_absolute()</code></td>
516 <p>[<a href="#path-query">path</a><br>
517 <a href="#path-query">.query</a>]</td>
533 <p><code>path</code> argument disambiguation between generic format and
536 <p>[<a href="#path-Conversions-to-native-format">path.arg</a><br>
537 <a href="#path-Conversions-to-native-format">.fmt.cvt</a>]</td>
543 <p>There is no need to distinguish between the generic format and native
544 format for these operating systems.</td>
548 <p><code>path</code> argument format conversion</td>
550 <p>[<a href="#path-Conversions-to-native-format">path.arg</a><br>
551 <a href="#path-Conversions-to-native-format">.fmt.cvt</a>]</td>
553 <p>No conversion performed</td>
555 <p>No conversion performed</td>
557 <p>The generic format is already acceptable to the native API of these operating systems.</td>
562 ("/cats/jane")<br>
565 ("/cats/jane/")<br>
566 .c_str()</code></td>
568 <p>[<a href="#path-Conversions-to-native-format">path.arg</a><br>
569 <a href="#path-Conversions-to-native-format">.fmt.cvt</a>]</td>
573 "/cats/jane"<br>
576 "/cats/jane/"</code></td>
580 L"/cats/jane"<br>
583 L"/cats/jane/"</code></td>
585 <p>These operating systems accept the same native separator between
586 directory names and a final file name, so no format conversion is performed.
587 Other operating systems might require conversion.</td>
591 <p>Format conversion by <code>path</code> native format observers</td>
593 <p>[<a href="#path-native-format-observers">path.native</a><br>
594 <a href="#path-native-format-observers">.obs</a>]</td>
596 <p>No conversion performed</td>
598 <p>No conversion performed</td>
600 <p>For efficiency, <code>path</code> objects are required to store pathnames in the native
601 format regardless of operating system.</td>
605 <p>Format conversion by <code>path</code> generic format observers</td>
607 <p>[<a href="#path-generic-format-observers">path</a><br>
608 <a href="#path-generic-format-observers">.generic</a><br>
609 <a href="#path-generic-format-observers">.obs</a>]</td>
611 <p>No conversion performed</td>
613 <p>Backslashes converted to slashes</td>
620 make_preferred()</code></td>
622 <p>[<a href="#path-modifiers">fs.path</a><br>
623 <a href="#path-modifiers">.modifiers</a>]</td>
627 <p>Slashes converted to backslashes</td>
633 <p>Characters prohibited in filenames</td>
635 <p>[<a href="#filename">fs.def</a><br>
636 <a href="#filename">.filename</a>]</td>
638 <p>0x00, <code>'/'</code></td>
640 <p>0x00-0x1F, <code>'"'</code>, <code>'*'</code>,<code> '*'</code>,
642 <code>'>'</code>, <code>'?'</code>, <code>'\\'</code> (single backslash),
643 <code>'/'</code>, <code>'|'</code></td>
645 <p>Many operating systems prohibit the ASCII control characters (0x00-0x1F)
650 <p>Initial imbued <code>path</code> locale</td>
652 <p>[<a href="#path-imbued-locale">path</a><br>
653 <a href="#path-imbued-locale">.imbued</a><br>
654 <a href="#path-imbued-locale">.locale</a>]</td>
657 locale("")<br>
658 </code><sup>[footnote 2]</sup></td>
660 <p>Implementation supplied locale using <code>MultiByte<br>
661 ToWideChar</code>
662 and <code>WideChar<br>
663 ToMultiByte</code> with a codepage of <code>CP_ACP</code>
664 if <code>AreFileApisANSI</code> is true, otherwise codepage <code>CP_OEMCP</code>.<sup>[footnote
667 <p>Apple OS X®: Implementation supplied locale providing UTF-8 <code>codecvt</code>
668 facet.<sup>[footnote 4]</sup></td>
671 <p><sup>[footnote1]</sup> OS X® and Windows® are examples of commercially
672 available operating systems. This information is given for the convenience of
673 users of this document and does not constitute an endorsement by ISO or IEC of
675 <p><sup>[footnote 2] </sup>Rationale: ISO C specifies <code>std::locale("")</code> as "the locale-specific native
676 environment", while ISO/IEC 9945 says it "Specifies an implementation-defined native
677 environment."</p>
678 <p><sup>[footnote 3] </sup>Rationale: This is the current behavior of C and C++
679 standard library functions that perform file operations using narrow character
680 strings to identify paths. Changing this behavior would be surprising and at
681 variance with existing code, particularly where user input is involved.</p>
682 <p><sup>[footnote 4]</sup> Rationale: Vendor's documentation states "All BSD
683 system functions expect their string parameters to be in UTF-8 encoding and
684 nothing else."</p>
685 <h2><a name="Header-filesystem-synopsis">Header <code><boost/filesystem.hpp></code> synopsis</a>
686 [filesystem.synopsis]</h2>
694 class <a href="#class-path">path</a>;
696 bool lexicographical_compare(path::iterator first1, path::iterator last1,
697 path::iterator first2, path::iterator last2);
698 void swap(path& lhs, path& rhs);
699 std::size_t <a href="#hash_value">hash_value</a>(const path& p);
701 bool operator==(const path& lhs, const path& rhs);
702 bool operator!=(const path& lhs, const path& rhs);
703 bool operator< (const path& lhs, const path& rhs);
704 bool operator<=(const path& lhs, const path& rhs);
705 bool operator> (const path& lhs, const path& rhs);
706 bool operator>=(const path& lhs, const path& rhs);
708 path operator/ (const path& lhs, const path& rhs);
710 std::ostream& operator<<( std::ostream& os, const path& p );
711 std::wostream& operator<<( std::wostream& os, const path& p );
712 std::istream& operator>>( std::istream& is, path& p );
713 std::wistream& operator>>( std::wistream& is, path& p )
715 class <a href="#Class-filesystem_error">filesystem_error</a>;
716 class <a href="#Class-directory_entry">directory_entry</a>;
718 class <a href="#Class-directory_iterator">directory_iterator</a>;
720 // enable c++11 range-based for statements
721 const directory_iterator& <a href="#directory_iterator-non-member-functions">begin</a>(const directory_iterator& iter);
722 directory_iterator <a href="#directory_iterator-non-member-functions">end</a>(const directory_iterator&);
725 // enable BOOST_FOREACH
726 directory_iterator& range_begin(directory_iterator& iter);
727 directory_iterator range_begin(const directory_iterator& iter);
728 directory_iterator range_end(const directory_iterator&);
730 class <a href="#Class-recursive_directory_iterator">recursive_directory_iterator</a>;
732 // enable c++11 range-based for statements
733 const recursive_directory_iterator&
734 <a href="#recursive_directory_iterator-non-member-functions">begin</a>(const recursive_directory_iterator& iter);
735 recursive_directory_iterator
736 <a href="#recursive_directory_iterator-non-member-functions">end</a>(const recursive_directory_iterator&);
739 // enable BOOST_FOREACH
740 recursive_directory_iterator&
741 range_begin(recursive_directory_iterator& iter);
742 recursive_directory_iterator
743 range_begin(const recursive_directory_iterator& iter);
744 recursive_directory_iterator
745 range_end(const recursive_directory_iterator&);
747 enum <a name="file_type" href="#Enum-file_type">file_type</a>
749 status_error, file_not_found, regular_file, directory_file,
750 symlink_file, block_file, character_file, fifo_file, socket_file,
754 enum <a href="#Enum-perms">perms</a>
757 owner_read, owner_write, owner_exe, owner_all,
758 group_read, group_write, group_exe, group_all,
759 others_read, others_write, others_exe, others_all, all_all,
760 set_uid_on_exe, set_gid_on_exe, sticky_bit,
761 perms_mask, perms_not_known,
762 add_perms, remove_perms, symlink_perms
765 class <a href="#file_status">file_status</a>;
767 struct <a name="space_info">space_info</a> // returned by <a href="#space" style="text-decoration: none">space</a> function
771 uintmax_t available; // free space available to non-privileged process
774 enum class <a name="copy_option">copy_option</a>
777 fail_if_exists = none,
781 enum class <a name="directory_options">directory_options</a>
784 skip_permission_denied,
785 follow_directory_symlink,
789 // Deprecated, use <a href="#directory_options">directory_options</a> instead
790 enum class <a name="symlink_option">symlink_option</a>
792 none = directory_options::none
794 recurse = directory_options::follow_directory_symlink
797 // <a href="#Operational-functions">operational functions</a>
799 path <a href="#absolute">absolute</a>(const path& p, const path& base=current_path());
801 path <a href="#canonical">canonical</a>(const path& p, const path& base = current_path());
802 path <a href="#canonical">canonical</a>(const path& p, system::error_code& ec);
803 path <a href="#canonical">canonical</a>(const path& p, const path& base,
804 system::error_code& ec);
806 void <a href="#copy">copy</a>(const path& from, const path& to);
807 void <a href="#copy">copy</a>(const path& from, const path& to,
808 system::error_code& ec);
810 void <a href="#create_directory">copy_directory</a>(const path& from, const path& to);
811 void <a href="#create_directory">copy_directory</a>(const path& from, const path& to,
812 system::error_code& ec);
814 void <a href="#copy_file">copy_file</a>(const path& from, const path& to);
815 void <a href="#copy_file">copy_file</a>(const path& from, const path& to,
816 system::error_code& ec);
817 void <a href="#copy_file">copy_file</a>(const path& from, const path& to,
818 <a href="#copy_option">copy_option</a> option);
819 void <a href="#copy_file">copy_file</a>(const path& from, const path& to,
820 <a href="#copy_option">copy_option</a> option, system::error_code& ec);
822 void <a href="#copy_symlink">copy_symlink</a>(const path& existing_symlink,
823 const path& new_symlink);
824 void <a href="#copy_symlink">copy_symlink</a>(const path& existing_symlink,
825 const path& new_symlink, system::error_code& ec);
827 bool <a href="#create_directories">create_directories</a>(const path& p);
828 bool <a href="#create_directories">create_directories</a>(const path& p,
829 system::error_code& ec);
831 bool <a href="#create_directory">create_directory</a>(const path& p);
832 bool <a href="#create_directory">create_directory</a>(const path& p, system::error_code& ec);
834 void <a href="#create_directory_symlink">create_directory_symlink</a>(const path& to,
835 const path& new_symlink);
836 void <a href="#create_directory_symlink">create_directory_symlink</a>(const path& to,
837 const path& new_symlink, system::error_code& ec);
839 void <a href="#create_hard_link">create_hard_link</a>(const path& to, const path& new_hard_link);
840 void <a href="#create_hard_link">create_hard_link</a>(const path& to, const path& new_hard_link,
841 system::error_code& ec);
843 void <a href="#create_symlink">create_symlink</a>(const path& to, const path& new_symlink);
844 void <a href="#create_symlink">create_symlink</a>(const path& to, const path& new_symlink,
845 system::error_code& ec);
847 path <a href="#current_path">current_path</a>();
848 path <a href="#current_path">current_path</a>(system::error_code& ec);
849 void <a href="#current_path">current_path</a>(const path& p);
850 void <a href="#current_path">current_path</a>(const path& p, system::error_code& ec);
852 bool <a href="#exists">exists</a>(file_status s) noexcept;
853 bool <a href="#exists">exists</a>(const path& p);
854 bool <a href="#exists">exists</a>(const path& p, system::error_code& ec) noexcept;
856 bool <a href="#equivalent">equivalent</a>(const path& p1, const path& p2);
857 bool <a href="#equivalent">equivalent</a>(const path& p1, const path& p2,
858 system::error_code& ec);
860 uintmax_t <a href="#file_size">file_size</a>(const path& p);
861 uintmax_t <a href="#file_size">file_size</a>(const path& p, system::error_code& ec);
863 uintmax_t <a href="#hard_link_count">hard_link_count</a>(const path& p);
864 uintmax_t <a href="#hard_link_count">hard_link_count</a>(const path& p, system::error_code& ec);
866 const path& <a href="#initial_path">initial_path</a>();
867 const path& <a href="#initial_path">initial_path</a>(<code>system::error_code& ec</code>);
869 bool <a href="#is_directory">is_directory</a>(file_status s) noexcept;
870 bool <a href="#is_directory2">is_directory</a>(const path& p);
871 bool <a href="#is_directory2">is_directory</a>(const path& p,
872 system::error_code& ec) noexcept;
874 bool <a href="#is_empty">is_empty</a>(const path& p);
875 bool <a href="#is_empty">is_empty</a>(const path& p, system::error_code& ec);
877 bool <a href="#is_other">is_other</a>(file_status s) noexcept;
878 bool <a href="#is_other2">is_other</a>(const path& p,);
879 bool <a href="#is_other2">is_other</a>(const path& p, system::error_code& ec) noexcept;
881 bool <a href="#is_regular_file">is_regular_file</a>(file_status s) noexcept;
882 bool <a href="#is_regular_file2">is_regular_file</a>(const path& p);
883 bool <a href="#is_regular_file2">is_regular_file</a>(const path& p,
884 system::error_code& ec) noexcept;
886 bool <a href="#is_symlink">is_symlink</a>(file_status s noexcept);
887 bool <a href="#is_symlink2">is_symlink</a>(const path& p);
888 bool <a href="#is_symlink2">is_symlink</a>(const path& p, system::error_code& ec) noexcept;
890 std::time_t <a href="#last_write_time">last_write_time</a>(const path& p);
891 std::time_t <a href="#last_write_time">last_write_time</a>(const path& p, system::error_code& ec);
892 void <a href="#last_write_time2">last_write_time</a>(const path& p, const std::time_t new_time);
893 void <a href="#last_write_time2">last_write_time</a>(const path& p, const std::time_t new_time,
894 system::error_code& ec);
896 path <a href="#read_symlink">read_symlink</a>(const path& p);
897 path <a href="#read_symlink">read_symlink</a>(const path& p, system::error_code& ec);
899 path <a href="#op-relative">relative</a>(const path& p, system::error_code& ec);
900 path <a href="#op-relative">relative</a>(const path& p, const path& base=current_path());
901 path <a href="#op-relative">relative</a>(const path& p,
902 const path& base, system::error_code& ec);
904 bool <a href="#remove">remove</a>(const path& p);
905 bool <a href="#remove">remove</a>(const path& p, system::error_code& ec);
907 uintmax_t <a href="#remove_all">remove_all</a>(const path& p);
908 uintmax_t <a href="#remove_all">remove_all</a>(const path& p, system::error_code& ec);
910 void <a href="#rename">rename</a>(const path& from, const path& to);
911 void <a href="#rename">rename</a>(const path& from, const path& to,
912 system::error_code& ec);
914 void <a href="#resize_file">resize_file</a>(const path& p, uintmax_t size);
915 void <a href="#resize_file2">resize_file</a>(const path& p, uintmax_t size,
916 system::error_code& ec);
918 <a href="#space_info">space_info</a> <a href="#space">space</a>(const path& p);
919 <a href="#space_info">space_info</a> <a href="#space">space</a>(const path& p, system::error_code& ec);
921 <a href="#file_status">file_status</a> <a href="#status">status</a>(const path& p);
922 <a href="#file_status">file_status</a> <a href="#status">status</a>(const path& p, system::error_code& ec) noexcept;
924 bool <a href="#status_known">status_known</a>(file_status s) noexcept;
926 <a href="#file_status">file_status</a> <a href="#symlink_status">symlink_status</a>(const path& p);
927 <a href="#file_status">file_status</a> <a href="#symlink_status">symlink_status</a>(const path& p,
928 system::error_code& ec) noexcept;
930 path <a href="#system_complete">system_complete</a>(const path& p);
931 path <a href="#system_complete">system_complete</a>(const path& p, system::error_code& ec);
933 path <a href="#temp_directory_path">temp_directory_path</a>();
934 path <a href="#temp_directory_path">temp_directory_path</a>(system::error_code& ec);
936 path <a href="#unique_path">unique_path</a>(const path& model="%%%%-%%%%-%%%%-%%%%");
937 path <a href="#unique_path">unique_path</a>(const path& model, system::error_code& ec);
939 path <a href="#weakly_canonical">weakly_canonical</a>(const path& p);
940 path <a href="#weakly_canonical">weakly_canonical</a>(const path& p, system::error_code& ec);
942 } // namespace filesystem
943 } // namespace boost</pre>
947 <h2><a name="Error-reporting">Error reporting</a> [fs.err.report]</h2>
948 <p>Filesystem library functions often provide two overloads, one that
949 throws an exception to report file system errors, and another that sets an <code>error_code</code>.</p>
951 <p>[<i>Note:</i> This supports two common use cases:</p>
954 <p>Uses where file system
955 errors are truly exceptional and indicate a serious failure. Throwing an
956 exception is the most appropriate response. This is the preferred default for
957 most everyday programming.<br>
960 <p>Uses where file system errors are routine and do not necessarily represent
961 failure. Returning an error code is the most appropriate response. This allows
962 application specific error handling, including simply ignoring the error.</li>
964 <p><i>—end note</i>]</p>
966 <p>Functions <b>not</b> having an argument of type <code>system::error_code&</code> report errors as follows, unless otherwise specified:</p>
969 <p>When a call by the
970 implementation to an operating system or other underlying API results in an
971 error that prevents the function from meeting its specifications, an exception
973 <code>filesystem_error</code> is thrown.<br>
976 <p>Failure to allocate storage is reported by throwing an exception as described in the C++ standard,
977 17.6.4.10 [res.on.exception.handling].<br>
980 <p>Destructors throw nothing.</li>
982 <p>Functions having an argument of type <code>system::error_code&</code> report errors as follows, unless otherwise
987 implementation to an operating system or other underlying API results in an
988 error that prevents the function from meeting its specifications, the
989 <code>system::error_code&</code> argument is set as
990 appropriate for the specific error. Otherwise, <code>clear()</code>
992 <code>system::error_code&</code> argument.<br>
995 <p>Failure to allocate storage is reported by
996 throwing an exception as described in the C++ standard,
997 17.6.4.10 [res.on.exception.handling].</li>
999 <h2><a name="class-path">Class <code>path</code> [class.path]</a></h2>
1000 <p>An object of class <code>path</code> represents a <a href="#path">path</a>,
1001 and contains a <a href="#pathname">pathname</a> Such an object is concerned only with the lexical and syntactic aspects
1002 of a path. The path does not necessarily exist in external storage, and the
1003 pathname is not necessarily valid for the current operating
1004 system or for a particular file system.</p>
1008 <pre>namespace boost
1010 namespace filesystem
1015 typedef <b><i><a href="#value_type">see below</a></i></b> value_type;
1016 typedef std::basic_string<value_type> string_type;
1017 typedef std::codecvt<wchar_t, char, std::mbstate_t> codecvt_type;
1018 constexpr value_type dot;
1019 constexpr value_type separator;
1020 constexpr value_type preferred_separator;
1022 // <a href="#path-constructors">constructors</a> and destructor
1024 path(const path& p);
1025 path(path&& p) noexcept;
1027 template <class <a href="#Source">Source</a>>
1028 path(Source const& source, const codecvt_type& cvt=codecvt());
1030 template <class <a href="#InputIterator">InputIterator</a>>
1031 path(InputIterator begin, InputIterator end,
1032 const codecvt_type& cvt=codecvt());
1036 // <a href="#path-assignments">assignments</a>
1037 path& operator=(const path& p);
1038 path& operator=(path&& p) noexcept;
1040 template <class <a href="#Source">Source</a>>
1041 path& operator=(Source const& source);
1043 template <class <a href="#Source">Source</a>>
1044 path& assign(Source const& source, const codecvt_type& cvt)
1046 template <class <a href="#InputIterator">InputIterator</a>>
1047 path& assign(InputIterator begin, InputIterator end,
1048 const codecvt_type& cvt=codecvt());
1050 // <a href="#path-appends">appends</a>
1051 path& operator/=(const path& p);
1053 template <class <a href="#Source">Source</a>>
1054 path& operator/=(Source const& source);
1056 template <class <a href="#Source">Source</a>>
1057 path& append(Source const& source, const codecvt_type& cvt);
1059 template <class <a href="#InputIterator">InputIterator</a>>
1060 path& append(InputIterator begin, InputIterator end,
1061 const codecvt_type& cvt=codecvt());
1063 // <a href="#path-concatenation">concatenation</a>
1064 path& operator+=(const path& x);
1065 path& operator+=(const string_type& x);
1066 path& operator+=(const value_type* x);
1067 path& operator+=(value_type x);
1068 template <class Source>
1069 path& operator+=(Source const& x);
1070 template <class CharT>
1071 path& operator+=(CharT x);
1072 template <class Source>
1073 path& concat(Source const& x, const codecvt_type& cvt);
1074 template <class InputIterator>
1075 path& concat(InputIterator begin, InputIterator end);
1076 template <class InputIterator>
1077 path& concat(InputIterator begin, InputIterator end,
1078 const codecvt_type& cvt);
1080 // <a href="#path-modifiers">modifiers</a>
1081 void <a href="#path-clear">clear</a>();
1082 path& <a href="#path-make_preferred">make_preferred</a>();
1083 path& <a href="#path-remove_filename">remove_filename</a>();
1084 path& <a href="#path-replace_extension">replace_extension</a>(const path& new_extension = path());
1085 void <a href="#path-swap">swap</a>(path& rhs);
1087 // lexical operations
1088 path <a href="#lexically_normal">lexically_normal</a>() const;
1089 path <a href="#lexically_relative">lexically_relative</a>(const path& base) const;
1090 path <a href="#lexically_proximate">lexically_proximate</a>(const path& base) const;
1092 // <a href="#path-native-format-observers">native format observers</a>
1093 const string_type& <a href="#native">native</a>() const noexcept; // native format, encoding
1094 const value_type* <a href="#c_str">c_str</a>() const noexcept; // native().c_str()
1095 string_type::size_type <a href="#path-size">size</a>() const noexcept; // native().size()
1097 template <class String>
1098 String <a href="#string-template">string</a>(const codecvt_type& cvt=codecvt()) const;
1099 string <a href="#string">string</a>(const codecvt_type& cvt=codecvt()) const;
1100 wstring <a href="#wstring">wstring</a>(const codecvt_type& cvt=codecvt()) const;
1101 u16string <a href="#u16string">u16string</a>() const;
1102 u32string <a href="#u32wstring">u32string</a>() const;
1104 // <a href="#path-generic-format-observers">generic format observers</a>
1105 template <class String>
1106 String <a href="#generic_string-template">generic_string</a>() const;
1108 string <a href="#generic_string">generic_string</a>(const codecvt_type& cvt=codecvt()) const;
1109 wstring <a href="#generic_wstring">generic_wstring</a>(const codecvt_type& cvt=codecvt()) const;
1110 u16string <a href="#generic_u16string">generic_u16string</a>()
1111 u32string <a href="#generic_u32wstring">generic_u32string</a>()
1113 // <a href="#path-compare">compare</a>
1114 int <a href="#path-compare">compare</a>(const path& p) const noexcept;
1115 int <a href="#path-compare">compare</a>(const std::string& s) const;
1116 int <a href="#path-compare">compare</a>(const value_type* s) const;
1118 // <a href="#path-decomposition">decomposition</a>
1119 path <a href="#path-root_name">root_name</a>() const;
1120 path <a href="#path-root_directory">root_directory</a>() const;
1121 path <a href="#path-root_path">root_path</a>() const;
1122 path <a href="#path-relative_path">relative_path</a>() const;
1123 path <a href="#path-parent_path">parent_path</a>() const;
1124 path <a href="#path-filename">filename</a>() const;
1125 path <a href="#path-stem">stem</a>() const;
1126 path <a href="#path-extension">extension</a>() const;
1128 // <a href="#path-query">query</a>
1129 bool <a href="#path-query">empty</a>() const;
1130 bool <a href="#filename_is_dot">filename_is_dot</a>() const;
1131 bool <a href="#filename_is_dot_dot">filename_is_dot_dot</a>() const;
1132 bool <a href="#path-has_root_name">has_root_name</a>() const;
1133 bool <a href="#path-has_root_directory">has_root_directory</a>() const;
1134 bool <a href="#path-has_root_path">has_root_path</a>() const;
1135 bool <a href="#path-has_relative_path">has_relative_path</a>() const;
1136 bool <a href="#path-has_parent_path">has_parent_path</a>() const;
1137 bool <a href="#path-has_filename">has_filename</a>() const;
1138 bool <a href="#path-has_stem">has_stem</a>() const;
1139 bool <a href="#path-has_extension">has_extension</a>() const;
1140 bool <a href="#path-is_absolute">is_absolute</a>() const;
1141 bool <a href="#path-is_relative">is_relative</a>() const;
1143 // <a href="#path-iterators">iterators</a>
1145 typedef iterator const_iterator;
1146 class reverse_iterator;
1147 typedef reverse_iterator const_reverse_iterator;
1149 iterator begin() const;
1150 iterator end() const;
1151 reverse_iterator rbegin() const;
1152 reverse_iterator rend() const;
1154 // <a href="#path-imbued-locale">imbued locale</a>
1155 static std::locale <a href="#path-imbue">imbue</a>(const std::locale& loc);
1156 static const codecvt_type & <a href="#path-codecvt">codecvt</a>();
1159 string_type pathname; // <b><i>exposition only</i></b>
1162 } // namespace filesystem
1163 } // namespace boost</pre>
1167 <p><code><a name="value_type">value_type</a></code> is a <code>typedef</code> for the
1168 character type used by the operating system to represent pathnames.</p>
1171 <h3><a name="path-Usage"><code>path</code> Usage concerns</a> [path.usage]</h3>
1173 <h4>Multithreading concerns</h4>
1175 <p>Filesystem library functions are not protected against data races. [Modifying
1176 an object of a Filesystem library type that is shared between threads risks
1177 undefined behavior unless objects of that type are explicitly specified as being
1178 sharable without data races or the user supplies a locking mechanism. <i>—end
1179 note</i>] [<i>Note:</i> Thus the Filesystem library behaves as if it were part
1180 of the standard library, and C++ standard 17.6.4.10 <i>Shared objects and the
1181 library</i> [res.on.objects] would thus apply. <i>—end note</i>]</p>
1183 <h4>Windows concerns</h4>
1185 <p>Visual C++ at least through version 2012 does not employ C++11-style static
1186 initialization locks, so the initialization of <code>path::codecvt()</code> can
1187 race, either with itself or <code>path::imbue::()</code> if they are called from
1188 a different thread. A workaround is to call:</p>
1191 <p><code>path::codecvt(); // ensure VC++ does not race during
1192 initialization.</code></p>
1195 <p>in the main thread before launching any additional threads. [<i>Note:</i> The
1196 obvious fix of the Filesystem implementation doing the locking doesn't work
1197 because of unrelated problems with the Microsoft compiler; for static linking
1198 the runtime tries to do the initialization before main() starts, but doesn't
1199 permit operating system lock calls at that time. <i>—end note</i>]</p>
1201 <h4>POSIX concerns</h4>
1203 <p>Filesystem library initialization may throw an exception on POSIX
1204 systems (e.g. Linux, but not Mac OS X) that use environmental variables to
1205 determine the encoding of paths. This happens when <code>std::locale("")</code>
1206 throws because an environmental variable such as LANG is set to an invalid
1207 value, so it can affect any use of <code>std::locale("")</code>, not just
1208 the Filesystem library. Filesystem uses lazy initialization so the exception is
1209 only thrown if a valid <code>std::locale("")</code> is actually needed, and also
1210 so that the exception is thrown after <code>main()</code> starts.</p>
1212 <p>Rather than waiting until a call to some Filesystem library function
1213 unexpectedly triggers the exception when it calls <code>path::codecvt()</code>,
1214 a program that needs be highly robust against environmental variable problems
1215 may want to preemptively call <code>std::locale("")</code> within a try block,
1216 catch the exception, and diagnose or repair the invalid environmental variable.</p>
1218 <h3><a name="path-Conversions"><code>path</code> Conversions</a> [path.cvt]</h3>
1219 <h4><code>path</code> argument conversions [<a name="path.arg.convert">path.arg.cvt</a>]</h4>
1220 <h5><a name="path-Conversions-to-native-format"><code>path</code> argument
1221 format conversions</a> [path.arg.fmt.cvt]</h5>
1222 <p>Member function arguments that take character sequences representing paths
1223 may use the <a href="#generic-pathname-format">generic pathname format</a> or
1224 the <a href="#native-pathname-format">native pathname format</a>. Iff such arguments
1225 are in the generic format and the generic format is not acceptable to the
1226 operating system as a native path, conversion to native format shall be performed
1227 during the processing of the argument. See [<a href="#Operating-system-examples">fs.os.examples</a>].</p>
1229 <p>[<i>Note:</i> Depending on the operating system, there may be no unambiguous way for an implementation to
1230 always be able to distinguish between native format and generic format arguments.
1231 This is by design as it simplifies use for operating systems that do not require
1232 disambiguation. Should an implementation encounter an
1233 operating system where disambiguation is required, an implementation can defined
1234 an extension to distinguish between the formats. <i>
1235 —end note</i>]</p>
1238 <p>If the native format requires
1239 paths for regular files to be formatted differently from paths for directories, the
1240 path shall be treated as a directory path if last element is a separator,
1241 otherwise it shall be treated as a regular file path.</p>
1243 <h5><a name="path-Encoding-conversions"><code>
1244 path</code> argument encoding conversions</a>
1245 [path.arg.encoding.cvt]</h5>
1246 <p>For member function arguments that take character sequences representing
1247 paths, if the value type of the argument is not <code>value_type and </code>one
1248 of the value types is <code>char</code> and the other is <code>wchar_t</code>, conversion to <code>value_type</code>
1249 shall be performed by the <code>path::codecvt()</code> facet. ([<a href="#path-imbued-locale">path.imbued.locale</a>]).</p>
1250 <h4><a name="path-Conversions-to-generic-format"><code>path</code> Conversions
1251 to generic format</a> [fs.cvt.to.generic]</h4>
1252 <p><a href="#path-generic-format-observers">Generic format observer</a> functions
1253 shall return strings formatted according to the <a href="#generic-pathname-format">generic pathname format</a>
1254 using <i>preferred-separator</i>. See [<a href="#Operating-system-examples">fs.os.examples</a>].</p>
1255 <h3><a name="path-Requirements"><code>path</code> Requirements</a> [path.req]</h3>
1256 <p>Template parameters named <code><a name="InputIterator">InputIterator</a></code> are required meet the
1257 requirements for a C++ standard library <code>RandomIterator</code> compliant iterator. The iterator's value type is required to be <code>char</code>, <code>wchar_t</code>, <code>char16_t</code>, or <code>char32_t</code>.</p>
1258 <p>Template parameters named <code><a name="Source">Source</a></code> are required to be one of:</p>
1261 <p>A container with a value type of <code>char</code>, <code>
1262 wchar_t</code>, <code>char16_t</code>, or <code>char32_t</code>.</li>
1264 <p>An iterator for a null terminated byte-string. The value type is required
1265 to be <code>char</code>, <code>wchar_t</code>, <code>char16_t</code>, or <code>
1266 char32_t</code>.</li>
1268 <p>A C-array. The value type is required to be <code>char</code>, <code>
1269 wchar_t</code>, <code>char16_t</code>, or <code>char32_t</code>.</li>
1271 <p>A <code>boost::filesystem::directory_entry</code>.</li>
1274 <h3> <a name="path-constructors"> <code>
1275 <font size="4">path</font></code> constructors</a> [path.construct]</h3>
1277 <pre>template <class <a href="#Source">Source</a>>
1278 path(Source const& source, const codecvt_type& cvt=codecvt());</pre>
1281 <pre>template <class <a href="#InputIterator">InputIterator</a>>
1282 path(InputIterator begin, InputIterator end, const codecvt_type& cvt=codecvt());</pre>
1285 <p><i>Effects:</i> Stores the contents [<code>begin</code>,<code>end</code>)
1286 or <code>source</code> in <code>pathname</code>, converting format and
1287 encoding if required ([<a href="#path.arg.convert">path.arg.convert</a>]).</p>
1289 <h3> <a name="path-assignments"> <code>
1290 <font size="4">path</font></code> assignments</a> [path.assign]</h3>
1292 <pre>template <class <a href="#Source">Source</a>>
1293 path& operator=(Source const& source);
1294 template <class <a href="#Source">Source</a>>
1295 path& assign(Source const& source, const codecvt_type& cvt);
1296 template <class <a href="#InputIterator">InputIterator</a>>
1297 path& assign(InputIterator begin, InputIterator end, const codecvt_type& cvt=codecvt());</pre>
1300 <p><i>Effects:</i> Stores the contents [<code>begin</code>,<code>end</code>)
1301 or <code>source</code> in <code>pathname</code>, converting format and
1302 encoding if required ([<a href="#path.arg.convert">path.arg.convert</a>]). </p>
1304 <i>Returns: </i><code>*this</code></p>
1306 <h3><a name="path-appends"><code><font size="4"> path</font></code> appends</a>
1308 <p>The append operations use <code>
1309 operator/=</code> to denote their semantic effect of appending <i>
1310 preferred-separator</i> when needed. </p>
1312 <pre>path& operator/=(const path& p);</pre>
1315 <p><i>Effects:</i></p>
1317 <p>Appends <code>path::preferred_separator</code> to <code>pathname</code>,
1318 converting format and encoding if required ([<a href="#path.arg.convert">path.arg.convert</a>]), unless:</p>
1321 <p>an added separator
1322 would be redundant, or</li>
1324 <p>would change a relative path to an absolute path, or</li>
1326 <p><code>p.empty()</code>, or</li>
1328 <p><code>*p.native().cbegin()</code> is a directory separator.</li>
1330 <p>Then appends <code>p.native()</code> to <code>pathname</code>.</p>
1332 <p><i>Returns: </i><code>*this</code></p>
1335 <pre>template <class <a href="#Source">Source</a>>
1336 path& operator/=(Source const & source);
1337 template <class <a href="#Source">Source</a>>
1338 path& append(Source const & source, const codecvt_type& cvt);
1339 template <class <a href="#InputIterator">InputIterator</a>>
1340 path& append(InputIterator begin, InputIterator end, const codecvt_type& cvt=codecvt());</pre>
1343 <p><i>Effects:</i></p>
1345 <p>Appends <code>path::preferred_separator</code> to <code>pathname</code>, converting
1346 format and encoding if required ([<a href="#path.arg.convert">path.arg.convert</a>]), unless:</p>
1349 <p>an added separator
1350 would be redundant, or</li>
1352 <p>would change a relative path to an absolute path, or</li>
1354 <p><code>p.empty()</code>, or</li>
1356 <p><code>*p.native().cbegin()</code> is a separator.</li>
1358 <p>Appends the contents [<code>begin</code>,<code>end</code>)
1359 or <code>source</code> to <code>pathname</code>, converting format and
1360 encoding if required ([<a href="#path.arg.convert">path.arg.convert</a>]).</p>
1362 <p><i>Returns: </i><code>*this</code></p>
1365 <h3><a name="path-concatenation"><code>path</code> concatenation</a> [path.concat]</h3>
1367 <pre>path& operator+=(const path& x);
1368 path& operator+=(const string_type& x);
1369 path& operator+=(const value_type* x);
1370 path& operator+=(value_type x);
1371 template <class Source>
1372 path& operator+=(Source const& x);
1373 template <class CharT>
1374 path& operator+=(CharT x);
1375 template <class InputIterator>
1376 path& concat(InputIterator begin, InputIterator end);
1377 template <class InputIterator>
1378 path& concat(InputIterator begin, InputIterator end, const codecvt_type& cvt);</pre>
1380 <blockquote><p><i>Postcondition:</i> <code>native() == prior_native + <i>effective-argument</i></code>,
1381 where <code>prior_native</code> is <code>native()</code> prior to the call to <code>operator+=</code>,
1382 and <code><i>effective-argument</i></code> is:</p>
1384 <p><code>x.native()</code> if <code>x</code> is present and is <code>const path&</code>, otherwise</li>
1386 <p><code>s</code>, where <code>s</code> is
1387 <code>std::basic_string<typename std::iterator_traits<InputIterator>::value_type><br>s(begin, end)</code>,
1388 if <code>begin</code> and <code>end</code> arguments are present, otherwise</li>
1390 <p><code>x</code>.</li></ul><p>If the value type of <code><i>effective-argument</i></code> would not be <code>path::value_type</code>, the actual argument or argument range is first
1391 converted so that <code><i>effective-argument</i></code> has value type <code>path::value_type</code>.</li> </p>
1392 <p><i>Returns: </i><code>*this</code></p>
1394 <h3><a name="path-modifiers"> <code>
1395 path</code> modifiers</a> [path.modifiers]</h3>
1397 <pre>void <a name="path-clear">clear</a>();</pre>
1400 <p><i>Postcondition:</i> <code>this->empty()</code> is true.</p>
1403 <pre>path& <a name="path-make_preferred">make_preferred</a>();</pre>
1406 <p><i>Effects:</i> <i>directory-separator</i>s are converted to <i>preferred-separator</i>s.
1407 See [<a href="#Operating-system-examples">fs.os.examples</a>].</p>
1408 <p><i>Returns:</i> <code>*this</code></p>
1413 <pre>path& <a name="path-remove_filename">remove_filename</a>();</pre>
1416 <p><i>Returns: </i>As if, <code>*this = parent_path();</code></p>
1417 <p>[<i>Note:</i> This function is needed to efficiently implement <code>directory_iterator</code>. It is exposed to allow additional uses. The actual
1418 implementation may be much more efficient than <code>*this = parent_path()</code> <i>—end
1422 <pre>path& <a name="path-replace_extension">replace_extension</a>(const path& new_extension = path());</pre>
1425 <p><i>Effects:</i></p>
1428 <p>Any existing <code>extension()</code> is removed from the stored path,
1432 <code>new_extension</code> is not empty and does not begin with a dot
1433 character, a dot character is appended to the stored path, then</li>
1436 <code>new_extension</code> is appended to the stored path.</li>
1438 <p><i>Returns:</i> <code>*this</code></p>
1441 <pre><code>void <a name="path-swap">swap</a>(path& rhs) noexcept;</code></pre>
1444 <p><i>Effects:</i> Swaps the contents of the two paths.</p>
1445 <p><i>Complexity: </i>constant time.</p>
1448 <h3><a name="path-lexical-operations"><code>path</code> lexical operations</a>
1450 <pre>path <a name="lexically_normal">lexically_normal</a>() const;</pre>
1452 <p><i>Overview:</i> Returns <code>*this</code> with redundant current directory
1453 (<i>dot</i>), parent directory (<i>dot-dot</i>), and <i>directory-separator</i> elements removed.</p>
1454 <p><i>Returns:</i> <code>*this</code> in <a href="#normal-form">normal form</a>.</p>
1455 <p><i>Remarks:</i> Uses <code>operator/=</code> to compose the returned path.</p>
1456 <p>[<i>Example:</i></p>
1457 <p><code>assert(path("foo/./bar/..").lexically_normal() == "foo");<br>
1458 assert(path("foo/.///bar/../").lexically_normal() == "foo/.");</code></p>
1459 <p>The above assertions will succeed.<i> </i>On Windows, the
1460 returned path's <i>directory-separator</i> characters will be backslashes rather than slashes, but that
1461 does not affect <code>path</code> equality.<i> —end example</i>]</p>
1464 <pre>path <a name="lexically_relative">lexically_relative</a>(const path& base) const;</pre>
1466 <p><i>Overview:</i> Returns <code>*this</code> made relative to <code>base</code>.
1467 Treats empty or identical paths as corner cases, not errors. Does not resolve
1468 symlinks. Does not first normalize <code>*this</code> or <code>base</code>.</p>
1470 <p><i>Remarks:</i> Uses <code>std::mismatch(begin(), end(), base.begin(), base.end())</code>, to determine the first mismatched element of
1471 <code>*this</code> and <code>base</code>. Uses <code>operator==</code> to
1472 determine if elements match. </p>
1474 <p><i>Returns:</i> </p>
1478 <code>path()</code> if the first mismatched element of <code>*this</code> is equal to <code>
1479 begin()</code> or the first mismatched element
1480 of <code>base</code> is equal to <code>base.begin()</code>, or<br>
1483 <code>path(".")</code> if the first mismatched element of <code>
1484 *this</code> is equal to <code>
1485 end()</code> and the first mismatched element
1486 of <code>base</code> is equal to <code>base.end()</code>, or<br>
1488 <li>An object of class <code>path</code> composed via application of <code>
1489 operator/= path("..")</code> for each element in the half-open
1491 mismatched element of <code>base</code>, <code>base.end()</code>), and then
1492 application of <code>operator/=</code> for each element in the half-open
1494 [first mismatched element of <code>*this</code>, <code>end()</code>).
1498 <p>[<i>Example:</i></p>
1499 <p><code>assert(path("/a/d").lexically_relative("/a/b/c") == "../../d");<br>
1500 assert(path("/a/b/c").lexically_relative("/a/d") == "../b/c");<br>
1501 assert(path("a/b/c").lexically_relative("a") == "b/c");<br>
1502 assert(path("a/b/c").lexically_relative("a/b/c/x/y") == "../..");<br>
1503 assert(path("a/b/c").lexically_relative("a/b/c") == ".");<br>
1504 assert(path("a/b").lexically_relative("c/d") == "");</code></p>
1505 <p>The above assertions will succeed.<i> </i>On Windows, the
1506 returned path's <i>directory-separator</i>s will be backslashes rather than
1507 forward slashes, but that
1508 does not affect <code>path</code> equality.<i> —end example</i>]</p>
1510 <p>[<i>Note:</i> If symlink following semantics are desired, use the operational function <code>
1511 <a href="#op-relative">relative</a></code> <i>—end note</i>]</p>
1513 <p>[<i>Note:</i> If <a href="#lexically_normal">normalization</a> is needed to ensure
1514 consistent matching of elements, apply <code><a href="#lexically_normal">lexically_normal()</a></code>
1515 to <code>*this</code>, <code>base</code>, or both. <i>—end note</i>]</p>
1517 <pre>path <a name="lexically_proximate">lexically_proximate</a>(const path& base) const;</pre>
1519 <p><i>Returns:</i> If <code>lexically_relative(base)</code> returns a non-empty path, returns that path.
1520 Otherwise returns <code>*this</code>.</p>
1522 <p>[<i>Note:</i> If symlink following semantics are desired, use the operational function <code>
1523 <a href="#op-relative">relative</a></code> <i>—end note</i>]</p>
1525 <p>[<i>Note:</i> If <a href="#lexically_normal">normalization</a> is needed to ensure
1526 consistent matching of elements, apply <code><a href="#lexically_normal">lexically_normal()</a></code>
1527 to <code>*this</code>, <code>base</code>, or both. <i>—end note</i>]</p>
1532 <h3> <a name="path-native-format-observers"><code><font size="4">path</font></code> native format observers</a>
1533 [path.native.obs]</h3>
1534 <p>The string returned by all native format observers is in the <a href="#native-pathname-format">native pathname format</a>.</p>
1536 <pre>const string_type& <a name="native">native</a>() const noexcept;</pre>
1539 <p><i>Returns:</i> <code>pathname</code>.</p>
1542 <pre>const value_type* <a name="c_str">c_str</a>() const noexcept;</pre>
1545 <p><i>Returns:</i> <code>pathname.c_str()</code>.</p>
1548 <pre>string_type::size_type <a name="path-size">size</a>() const noexcept;</pre>
1551 <p><i>Returns:</i> <code>pathname.size()</code>.</p>
1554 <pre>template <class String>
1555 String <a name="string-template">string</a>(const codecvt_type& cvt=codecvt()) const;</pre>
1558 <p><i>Returns:</i> <code>pathname</code>.</p>
1559 <p><i>Remarks:</i> If <code>string_type</code> is a different type than <code>String</code>, conversion is performed by <code>cvt</code>.</p>
1562 <pre>string <a name="string">string</a>(const codecvt_type& cvt=codecvt()) const;
1563 wstring <a name="wstring">wstring</a>(const codecvt_type& cvt=codecvt()) const;
1564 u16string <a name="u16string">u16string</a>() const;
1565 u32wstring <a name="u32wstring">u32wstring</a>() const; </pre>
1568 <p><i>Returns:</i> <code>pathname</code>.</p>
1569 <p><i>Remarks:</i> If <code>string_type</code> is a different type than
1570 function's return type, conversion is performed by <code>cvt</code>.</p>
1573 <h3> <a name="path-generic-format-observers"><code><font size="4">path</font></code> generic format observers</a>
1574 [path.generic.obs]</h3>
1575 <p>The string returned by all generic format observers is in the <a href="#generic-pathname-format">generic pathname format</a>.</p>
1577 <pre>template <class String>
1578 String <a name="generic_string-template">generic_string</a>(const codecvt_type& cvt=codecvt()) const;</pre>
1581 <p><i>Returns:</i> <code>pathname</code>.</p>
1582 <p><i>Remarks:</i> If <code>string_type</code> is a different type than <code>String</code>, conversion is performed by <code>cvt</code>.</p>
1585 <pre>string <a name="generic_string">generic_string</a>(const codecvt_type& cvt=codecvt()) const;
1586 wstring <a name="generic_wstring">generic_wstring</a>(const codecvt_type& cvt=codecvt()) const;
1587 u16string <a name="generic_u16string">generic_u16string</a>() const;
1588 u32wstring <a name="generic_u32wstring">generic_u32wstring</a>() const; </pre>
1591 <p><i>Returns:</i> <code>pathname</code>.</p>
1592 <p><i>Remarks:</i> If <code>string_type</code> is a different type than
1593 function's return type, conversion is performed by <code>cvt</code>.</p>
1596 <h3> <a name="path-compare"><code>path</code> compare</a> [path.compare]</h3>
1598 <pre>int compare(const path& p) const noexcept;</pre>
1601 <p><i>Returns:</i> A value less than 0 if the elements of <code>*this</code> are lexicographically less than the elements of <code>p</code>, otherwise a
1602 value greater than 0 if the elements of <code>*this</code> are
1603 lexicographically greater than the elements of <code>p</code>, otherwise 0.</p>
1604 <p>Remark: The elements are determined as if by iteration over the half-open
1605 range [<code>begin()</code>, <code>end()</code>) for <code>*this</code> and <code>p</code>.</p>
1608 <pre>int compare(const std::string& s) const</pre>
1611 <p><i>Returns:</i> <code>compare(path(s))</code>.</p>
1614 <pre>int compare(const value_type* s) const</pre>
1617 <p><i>Returns:</i> <code>compare(path(s))</code>.</p>
1619 <h3> <a name="path-decomposition"> <code><font size="4">path</font></code> decomposition</a>
1620 [path.decompose]</h3>
1621 <p><span style="background-color: #E0E0E0"><i>See the <a href="#path-decomposition-table">Path decomposition table</a> for examples
1622 for values returned by decomposition functions. The <a href="tutorial.html#Using-path-decomposition">Tutorial</a> may also be
1623 helpful.</i></span></p>
1625 <pre>path <a name="path-root_name">root_name</a>() const;</pre>
1628 <p><i>Returns:</i> <i>root-name,</i> if <code>pathname</code> includes <i>root-name</i>, otherwise <code>path()</code>. </p>
1631 <pre>path <a name="path-root_directory">root_directory</a>() const;</pre>
1634 <p><i>Returns:</i> <i>root-directory</i>, if <code>pathname</code> includes <i>root-directory</i>, otherwise <code>path()</code>.</p>
1635 <p>If <i>root-directory</i> is composed of <i>slash name</i>, <i>slash</i> is
1636 excluded from the returned string.</p>
1639 <pre>path <a name="path-root_path">root_path</a>() const;</pre>
1642 <p><i>Returns:</i> <code>root_name() / root_directory()</code></p>
1645 <pre>path <a name="path-relative_path">relative_path</a>() const;</pre>
1648 <p><i>Returns:</i> A <code>path</code> composed from <code>pathname</code>, if <code>!empty()</code>, beginning
1649 with the first <i>filename</i> after <i>root-path</i>. Otherwise, <code>path()</code>.</p>
1652 <pre>path <a name="path-parent_path">parent_path</a>() const;</pre>
1655 <p><i>Returns:</i> <code>(empty() || begin() == —end()) ? path() : <i>pp</i></code>, where <code><i>pp</i></code> is constructed as if by
1656 starting with an empty <code>path</code> and successively applying <code>operator/=</code> for each element in the range <code>begin()</code>, <code>—end()</code>.</p>
1657 <p>[<i>Example:</i></p>
1660 <pre>std::cout << path("/foo/bar.txt").parent_path(); // outputs "/foo"
1661 std::cout << path("/foo/bar").parent_path(); // outputs "/foo"
1662 std::cout << path("/foo/bar/").parent_path(); // outputs "/foo/bar"
1663 std::cout << path("/").parent_path(); // outputs ""
1664 std::cout << path(".").parent_path(); // outputs ""
1665 std::cout << path("..").parent_path(); // outputs ""</pre>
1668 <p> See the last bullet item in the <a href="#path-iterators">
1669 forward traversal order</a> list for why the <code>"/foo/bar/"</code> example
1670 doesn't output <code>"/foo"</code>.</p>
1671 <p> <i>—end example</i>]</p>
1674 <pre>path <a name="path-filename">filename</a>() const;</pre>
1677 <p><i>Returns:</i> <code>empty() ? path() : *—end()</code></p>
1678 <p>[<i>Example:</i></p>
1681 <pre>std::cout << path("/foo/bar.txt").filename(); // outputs "bar.txt"
1682 std::cout << path("/foo/bar").filename(); // outputs "bar"
1683 std::cout << path("/foo/bar/").filename(); // outputs "."
1684 std::cout << path("/").filename(); // outputs "/"
1685 std::cout << path(".").filename(); // outputs "."
1686 std::cout << path("..").filename(); // outputs ".."</pre>
1689 <p> See the last bullet item in the <a href="#path-iterators">
1690 forward traversal order</a> list for why the <code>"/foo/bar/"</code> example
1691 doesn't output <code>"bar"</code>.</p>
1692 <p> <i>—end example</i>]</p>
1695 <pre>path <a name="path-stem">stem</a>() const;</pre>
1698 <p><i>Returns:</i> if <code>p.filename()</code> contains a dot but does not
1699 consist solely of one or to two dots, returns
1700 the substring of <code>p.filename()</code> starting at its beginning and
1701 ending at the last dot (the dot is not included). Otherwise,
1702 returns <code>p.filename()</code>.</p>
1703 <p>[<i>Example:</i></p>
1706 <pre><code>std::cout << path("/foo/bar.txt").stem();</code> // outputs "<code>bar</code>"
1707 path p = "foo.bar.baz.tar";
1708 for (; !p.extension().empty(); p = p.stem())
1709 std::cout << p.extension() << '\n';
1715 <p> <i>—end example</i>]</p>
1718 <pre>path <a name="path-extension">extension</a>() const;</pre>
1721 <p><i>Returns:</i> if <code>p.filename()</code> contains a dot but does not
1722 consist solely of one or to two dots, returns
1723 the substring of <code>p.filename()</code> starting at the rightmost dot
1724 and ending at the path's end. Otherwise, returns an empty <code>path</code> object. </p>
1725 <p><i>Remarks:</i> Implementations are permitted but not required to define additional
1726 behavior for file systems which append additional elements to extensions, such
1727 as alternate data streams or partitioned dataset names.</p>
1728 <p>[<i>Example:</i></p>
1731 <pre><code>std::cout << path("/foo/bar.txt").extension(); //</code> outputs "<code>.txt</code>"</pre>
1734 <p> <i>—end example</i>]</p>
1735 <p>[<i>Note:<b> </b></i>The dot is included in the return value so that it is
1736 possible to distinguish between no extension and an empty extension.
1737 See <a href="http://permalink.gmane.org/gmane.comp.lib.boost.devel/199744">
1738 http://permalink.gmane.org/gmane.comp.lib.boost.devel/199744</a> for more
1739 extensive rationale. <i>—end note</i>]</p>
1741 <h3> <a name="path-query"> <code><font size="4">path</font></code> query</a> [path.query]</h3>
1743 <pre>bool <a name="path-empty">empty</a>() const;</pre>
1746 <p><i>Returns:</i> <code>m_pathname.empty()</code>.</p>
1749 <pre>bool <a name="filename_is_dot">filename_is_dot</a>() const;</pre>
1752 <p><i>Returns:</i> <code>filename() == path(".")</code></p>
1753 <p>[<i>Example:</i></p>
1756 <pre>std::cout << path(".").filename_is_dot(); // outputs 1
1757 std::cout << path("/.").filename_is_dot(); // outputs 1
1758 std::cout << path("foo/.").filename_is_dot(); // outputs 1
1759 std::cout << path("foo/").filename_is_dot(); // outputs 1
1760 std::cout << path("/").filename_is_dot(); // outputs 0
1761 std::cout << path("/foo").filename_is_dot(); // outputs 0
1762 std::cout << path("/foo.").filename_is_dot(); // outputs 0
1763 std::cout << path("..").filename_is_dot(); // outputs 0</pre>
1766 <p> See the last bullet item in the <a href="#path-iterators">forward traversal order</a>
1767 list for why <code>path("foo/").filename()</code> is a dot filename.</p>
1768 <p> <i>—end example</i>]</p>
1771 <pre>bool <a name="filename_is_dot_dot">filename_is_dot_dot</a>() const;</pre>
1774 <p><i>Returns:</i> <code>filename() == path("..")</code></p>
1777 <pre>bool <a name="path-has_root_path">has_root_path</a>() const;</pre>
1780 <p><i>Returns:</i> <code>!<a href="#path-root_path">root_path</a>().empty()</code></p>
1783 <pre>bool <a name="path-has_root_name">has_root_name</a>() const;</pre>
1786 <p><i>Returns:</i> <code>!<a href="#path-root_name">root_name</a>().empty()</code></p>
1789 <pre>bool <a name="path-has_root_directory">has_root_directory</a>() const;</pre>
1792 <p><i>Returns:</i> <code>!<a href="#path-root_directory">root_directory</a>().empty()</code></p>
1795 <pre>bool <a name="path-has_relative_path">has_relative_path</a>() const;</pre>
1798 <p><i>Returns:</i> <code>!<a href="#path-has_relative_path">relative_path</a>().empty()</code></p>
1801 <pre>bool <a name="path-has_parent_path">has_parent_path</a>() const;</pre>
1804 <p><i>Returns:</i> <code>!<a href="#path-parent_path">parent_path</a>().empty()</code></p>
1807 <pre>bool <a name="path-has_filename">has_filename</a>() const;</pre>
1810 <p><i>Returns:</i> <code>!<a href="#path-filename">filename</a>().empty()</code></p>
1813 <pre>bool <a name="path-has_stem">has_stem</a>() const;</pre>
1816 <p><i>Returns:</i> <code>!<a href="#path-stem">stem</a>().empty()</code></p>
1819 <pre>bool <a name="path-has_extension">has_extension</a>() const;</pre>
1822 <p><i>Returns:</i> <code>!<a href="#path-has_extension">extension</a>().empty()</code></p>
1825 <pre>bool <a name="path-is_absolute">is_absolute</a>() const;</pre>
1828 <p><i>Returns:</i> <code>true</code> if the elements of <code>root_path()</code> uniquely identify a directory, else <code>false</code>.</p>
1831 <pre>bool <a name="path-is_relative">is_relative</a>() const;</pre>
1834 <p><i>Returns:</i> <code>!is_absolute()</code>.</p>
1836 <h3> <a name="path-iterators"> <code>
1837 <font size="4">path</font></code> iterators</a> [path.itr]</h3>
1838 <p> Path iterators <code>iterator</code>, <code>const_iterator</code>,
1839 <code>reverse_iterator</code>, and <code>const_reverse_iterator</code> iterate over the elements of the stored pathname.</p>
1840 <p> Path iterators are constant iterators satisfying
1841 the requirements of a bidirectional iterator (C++ Std, 24.1.4 Bidirectional
1842 iterators [lib.bidirectional.iterators]). The <code>value_type</code> of
1843 an iterator is <code>path</code>.</p>
1845 <p> [<i>Note:</i> Path iterators store their value objects internally
1846 and when dereferenced return references to those internal objects. They cannot
1847 be used with iterator adaptors such as <code>std::reverse_iterator</code> that
1848 assume references obtained by dereferencing an iterator point to objects that
1849 out-live the iterator itself. <i>—end note</i>] </p>
1851 <p>Calling any non-const member function of a <code>path</code> object
1852 invalidates all iterators referring to elements of that object.</p>
1853 <p> The forward traversal order is as follows:</p>
1855 <li>The <i>root-name</i> element, if present.</li>
1856 <li>The <i>root-directory</i> element, if present, in the generic format. <i>
1857 [note:</i> the generic format is required to ensure lexicographical
1858 comparison works correctly. <i>—end note</i>]</li>
1859 <li>Each successive <i>filename</i> element, if present.</li>
1860 <li><i>Dot</i>, if one or more trailing non-root <i>slash</i>
1861 characters are present.|</li>
1864 <p>[<i>Note:</i> Treating the last element during iteration as <i>dot</i> when
1865 there is a trailing directory separator enables lexical (i.e. syntactic)
1866 distinction between paths to directories versus paths to regular files. Such a
1867 distinction is usually irrelevant on POSIX and Windows based operating
1868 systems, but may be a requirement on other operating systems. <i>—end note</i>]</p>
1870 <p>The backward traversal order is the reverse of forward traversal.</p>
1871 <pre>iterator begin() const;</pre>
1873 <p><i>Returns:</i> An iterator for the first element in forward traversal
1874 order. If no elements are present, the end iterator.</p>
1876 <pre>iterator end() const;</pre>
1878 <p><i>Returns:</i> The end iterator.</p>
1880 <pre>reverse_iterator rbegin() const;</pre>
1882 <p><i>Returns:</i> An iterator for the first element in backward traversal
1883 order. If no elements are present, the end iterator.</p>
1885 <pre>reverse_iterator rend() const;</pre>
1887 <p><i>Returns:</i> The end iterator.</p>
1889 <h3><a name="path-imbued-locale"><code><font size="4"> path</font></code>
1890 imbued locale</a> [path.imbued.locale]</h3>
1891 <p><code>path</code> operations sometimes require encoding conversions between
1892 <code>pathname</code> and some other string object where one of the value types
1893 is <code>char</code> and the other is <code>wchar_t</code>. Such conversions
1894 shall be performed by the <code>path::codecvt()</code> facet.</p>
1896 <p><span style="background-color: #FFFF00">[</span><i><span style="background-color: #FFFF00">Example:</span></i><span style="background-color: #FFFF00">
1897 ... </span><i><span style="background-color: #FFFF00">—end example</span></i><span style="background-color: #FFFF00">]</span></p>
1899 <pre>static std::locale <a name="path-imbue">imbue</a>(const std::locale& loc);</pre>
1901 <p><i>Effects:</i> Stores a copy of <code>loc</code> as the imbued <code>path</code>
1903 <p><i>Returns:</i> The previous imbued <code>path</code> locale.</p>
1904 <p><i>Remarks:</i> The initial value of the imbued <code>path</code> locale is
1905 operating system dependent. It shall be a locale with a <code>codecvt</code>
1906 facet for a <code>char</code> string encoding appropriate for the operating
1907 system. See ([<a href="#Operating-system-examples">fs.os.examples</a>]). </p>
1909 <pre>static const codecvt_type& <a name="path-codecvt">codecvt</a>();</pre>
1911 <p><i>Returns:</i> The <code>codecvt</code> facet for the imbued<code> path</code>
1916 <h3> <a name="path-deprecated-functions"><code><font size="4"> path</font></code> deprecated functions</a></h3>
1917 <p> Several member functions from previous versions of <code>class path</code> have been deprecated, either because they have been renamed or because the
1918 functionality is no longer desirable or has become obsolete.</p>
1919 <p> Deprecated functions available by default; will be suppressed if <code>BOOST_FILESYSTEM_NO_DEPRECATED</code> is defined:</p>
1921 <pre>path& remove_leaf() { return remove_filename(); }
1922 path leaf() const { return filename(); }
1923 path branch_path() const { return parent_path(); }
1924 bool has_leaf() const { return !m_path.empty(); }
1925 bool has_branch_path() const { return !parent_path().empty(); }</pre>
1927 <p> Deprecated functions not available by default; will be supplied if <code>BOOST_FILESYSTEM_DEPRECATED</code> is defined:</p>
1929 <pre>const std::string file_string() const { return native_string(); }
1930 const std::string directory_string() const { return native_string(); }
1931 const std::string native_file_string() const { return native_string(); }
1932 const std::string native_directory_string() const { return native_string(); }
1933 const string_type external_file_string() const { return native(); }
1934 const string_type external_directory_string() const { return native(); }</pre>
1937 <h3> <a name="path-non-member-functions"> <code><font size="4">path</font></code> non-member functions</a>
1938 [path.non-member]</h3>
1940 <pre>bool lexicographical_compare(path::iterator first1, path::iterator last1,
1941 path::iterator first2, path::iterator last2);</pre>
1943 <p><i>Returns:</i> <code>true</code> if the sequence of <code>native()</code> strings for the elements defined by the half-open range <code>[first1,last1)</code> is
1944 lexicographically less than the sequence of <code>native()</code> strings for
1945 the elements defined by the half-open range <code>[first2,last2)</code>. Returns <code>false</code> otherwise.</p>
1946 <p><i>Remarks:</i> If two sequences have the same number of elements and their
1947 corresponding elements are equivalent, then neither sequence is
1948 lexicographically less than the other. If one sequence is a prefix of the
1949 other, then the shorter sequence is lexicographically less than the longer
1950 sequence. Otherwise, the lexicographical comparison of the sequences yields
1951 the same result as the comparison of the first corresponding pair of elements
1952 that are not equivalent.</p>
1953 <p>[<i>Note:</i> A <code>path</code> aware <code>lexicographical_compare</code> algorithm is provided for historical reasons. <i>—end note</i>]</p>
1958 <pre>path <a name="lex-normal">lexically_normal</a>(const path& p);</pre>
1963 <p><i>Overview:</i> Returns <code>p</code> with redundant current
1964 directory (<i>dot</i>), parent directory (<i>dot-dot</i>), and <i>
1965 directory-separator</i> elements removed.</p>
1966 <p><i>Returns:</i> <code>p</code> in
1967 <a href="#normal-form">
1968 normal form</a>.</p>
1969 <p><i>Remarks:</i> Uses <code>operator/=</code> to compose the
1971 <p>[<i>Example:</i></p>
1972 <p><code>assert(lexically_normal("foo/./bar/..") == "foo");<br>
1973 assert(lexically_normal("foo/.///bar/../") == "foo/.");</code></p>
1974 <p>All of the above assertions will succeed.<i> </i>On Windows, the
1975 returned path's <i>directory-separator</i> characters will be backslashes
1976 rather than slashes, but that does not affect <code>path</code> equality.<i>
1977 —end example</i>]</p>
1982 <pre>path lexically_<a name="lex-relative">relative</a>(const path& p, const path& base);</pre>
1987 <p><i>Overview:</i> Returns <code>p</code> made relative to <code>
1988 base</code>. Treats empty or identical paths as corner cases, not errors. Does
1989 not resolve symlinks. Does not first normalize <code>p</code> or <code>base</code>.</p>
1990 <p><i>Remarks:</i> Uses <code>std::mismatch(p.begin(), p.end(),
1991 base.begin(), base.end())</code>, to determine the first mismatched element of
1992 <code>p</code> and <code>base</code>. Uses <code>operator==</code> to
1993 determine if elements match. </p>
1994 <p><i>Returns:</i> </p>
1997 <p><code>path()</code> if the first mismatched element of <code>p</code>
1998 is equal to <code>p.begin()</code> or the first mismatched element of <code>
1999 base</code> is equal to <code>base.begin()</code>, or<br>
2002 <p><code>path(".")</code> if the first mismatched element of <code>
2003 p</code> is equal to <code>p.end()</code> and the first mismatched element
2004 of <code>base</code> is equal to <code>base.end()</code>, or<br>
2007 <p>An object of class <code>path</code> composed via application
2008 of <code>operator/= path("..")</code> for each element in the half-open
2009 range [first mismatched element of <code>base</code>, <code>base.end()</code>),
2010 and then application of <code>operator/=</code> for each element in the
2011 half-open range [first mismatched element of <code>p</code>, <code>p.end()</code>).
2014 <p>[<i>Example:</i></p>
2015 <p><code>assert(lexically_relative("/a/d", "/a/b/c") == "../../d");<br>
2016 assert(lexically_relative("/a/b/c", "/a/d") == "../b/c");<br>
2017 assert(lexically_relative("a/b/c", "a") == "b/c");<br>
2018 assert(lexically_relative("a/b/c", "a/b/c/x/y") == "../..");<br>
2019 assert(lexically_relative("a/b/c", "a/b/c") == ".");<br>
2020 assert(lexically_relative("a/b", "c/d") == "");</code></p>
2021 <p>All of the above assertions will succeed.<i> </i>On Windows, the
2022 returned path's <i>directory-separator</i>s will be backslashes rather than
2023 forward slashes, but that does not affect <code>path</code> equality.<i> —end
2025 <p>[<i>Note:</i> If symlink following semantics are desired, use the
2026 operational function <code>
2027 <a href="#op-relative">
2028 relative</a></code> <i>—end note</i>]</p>
2029 <p>[<i>Note:</i> If <a href="#normal-form">normalization</a> is needed to ensure consistent matching of elements, wrap
2030 <code>p</code>, <code>base</code>, or both in calls <code>
2031 <a href="#lex-normal">
2032 lexically_normal()</a></code>. <i>—end note</i>]</p>
2034 <pre>void swap( path& lhs, path& rhs )</pre>
2036 <p><i>Effects: </i><code>lhs.swap(rhs)</code>.</p>
2038 <pre>std::size_t <a name="hash_value">hash_value</a> (const path& p);</pre>
2040 <p><i>Returns:</i> A hash value for the path <code>p</code>. If
2041 for two paths, <code>p1 == p2</code> then <code>hash_value(p1) == hash_value(p2)</code>.</p>
2042 <p>This allows paths to be used with <a href="../../functional/hash/index.html">Boost.Hash</a>.</p>
2044 <pre>bool operator< (const path& lhs, const path& rhs);</pre>
2046 <p><i>Returns:</i> <code>return lhs.compare(rhs.begin) < 0</code>.</p>
2048 <pre>bool operator<=(const path& lhs, const path& rhs);</pre>
2050 <p><i>Returns:</i> <code>!(rhs < lhs)</code>.</p>
2052 <pre>bool operator> (const path& lhs, const path& rhs);</pre>
2054 <p><i>Returns:</i> <code>rhs < lhs</code>.</p>
2056 <pre>bool operator>=(const path& lhs, const path& rhs);</pre>
2058 <p><i>Returns:</i> <code>!(lhs < rhs)</code>.</p>
2060 <pre>bool operator==(const path& lhs, const path& rhs);</pre>
2062 <p><i>Returns:</i> <code>!(lhs < rhs) && !(rhs < lhs)</code>.</p>
2063 <p>[<i>Note:</i> <a name="Path-equality">Path equality</a> and path
2064 equivalence have different semantics.</p>
2065 <p>Equality is determined by the <code>path</code> non-member <code>operator==</code>, which considers the two path's lexical
2066 representations only. Thus <code>path("foo") == "bar"</code> is never <code>true</code>.</p>
2067 <p>Equivalence is determined by the <a href="#equivalent"><code>equivalent()</code></a> non-member function, which determines if two paths <a href="#path">resolve</a> to the same file system entity.
2068 Thus <code>equivalent("foo", "bar")</code> will be <code>true</code> when both paths resolve to the same file.</p>
2069 <p>Programmers wishing to determine if two paths are "the same" must decide if
2070 "the same" means "the same representation" or "resolve to the same actual
2071 file", and choose the appropriate function accordingly. <i>—end note</i>]</p>
2073 <pre>bool operator!=(const path& lhs, const path& rhs);</pre>
2075 <p><i>Returns:</i> <code>!(lhs == rhs)</code>.</p>
2077 <pre>path operator/ (const path& lhs, const path& rhs);</pre>
2079 <p><i>Returns:</i> <code>path(lhs) /= rhs</code>.</p>
2081 <h3> <a name="path-non-member-operators"><code><font size="4">path</font></code></a><a name="path-inserter-extractor"> inserter
2082 and extractor</a> [path.io]</h3>
2083 <p> The inserter and extractor delimit the string with double-quotes (<code>"</code>)
2084 so that paths with embedded spaces will round trip correctly. Ampersand (<code>&</code>)
2085 is as an escape character, so the path can itself contain double quotes.</p>
2086 <pre>template <class Char, class Traits>
2087 std::basic_ostream<Char, Traits>& operator<<(std::basic_ostream<Char, Traits>& os,
2091 <p><i>Effects: </i>Insert characters into <code>os</code>:</p>
2094 <p>A double-quote.</p>
2097 <p>Each character in <code>p.string<std::basic_string<Char>>()</code>.
2098 If the character to be inserted is equal to the escape character or a
2099 double-quote, as determined by <code>operator==</code>, first insert the
2100 escape character.</p>
2103 <p>A double-quote.</p>
2106 <p><i>Returns:</i> <code>os</code></p>
2108 <pre>template <class Char, class Traits>
2109 inline std::basic_istream<Char, Traits>& operator>>(std::basic_istream<Char, Traits>& is,
2113 <p><i>Effects: </i><code> std::basic_string<Char> str;<br>
2114 is >> <a href="../../io/doc/quoted_manip.html">boost::io::quoted</a>(str, static_cast<Char>('&'));<br>
2115 p = str;</code></p>
2116 <p><i>Effects: </i>Extract characters from os:</p>
2118 <li>If the first character that would be extracted is equal to double-quote,
2119 as determined by <code>operator==</code>, then:<ul>
2120 <li>Discard the initial double-quote.</li>
2121 <li>Save the value and then turn off the <code>skipws</code> flag.</li>
2122 <li><code>p.clear()</code></li>
2123 <li>Until an unescaped double-quote character is reached or <code>
2124 is.not_good()</code>, extract characters from <code>os</code> and append
2125 them to <code>p</code>, except that if an escape character is reached,
2126 ignore it and append the next character to <code>p</code>.</li>
2127 <li>Discard the final double-quote character.</li>
2128 <li>Restore the <code>skipws</code> flag to its original value.</li>
2131 <li>Otherwise, <code>os >> p</code>.</li>
2133 <p><i>Returns:</i> <code>is</code></p>
2135 <h2><a name="Class-filesystem_error">Class <code>filesystem_error</code>
2136 [class.filesystem_error]</a></h2>
2137 <pre>namespace boost
2139 namespace filesystem
2141 class filesystem_error : public system_error
2145 filesystem_error(const filesystem_error&);
2146 <a href="#filesystem_error-2-arg">filesystem_error</a>(const std::string& what_arg,
2147 system::error_code ec);
2148 <a href="#filesystem_error-3-arg">filesystem_error</a>(const std::string& what_arg,
2149 const path& p1, system::error_code ec);
2150 <a href="#filesystem_error-4-arg">filesystem_error</a>(const std::string& what_arg,
2151 const path& p1, const path& p2, system::error_code ec);
2153 filesystem_error& filesystem_error(const filesystem_error&);
2154 ~filesystem_error();
2156 filesystem_error& operator=(const filesystem_error&);
2158 const path& <a href="#filesystem_error-path1">path1</a>() const;
2159 const path& <a href="#filesystem_error-path2">path2</a>() const;
2161 const char * <a href="#filesystem_error-what">what</a>() const;
2163 } // namespace filesystem
2164 } // namespace boost</pre>
2165 <p>The class template <code>filesystem_error</code> defines the type of
2166 objects thrown as exceptions to report file system errors from functions described in this
2167 reference documentation.</p>
2168 <h3> <a name="filesystem_error-members"> <code>filesystem_error</code> members</a>
2169 [filesystem_error.members]</h3>
2170 <pre><a name="filesystem_error-2-arg">filesystem_error</a>(const std::string& what_arg, error_code ec);</pre>
2172 <p><i>Postcondition:</i></p>
2173 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="46%">
2175 <td width="18%"><b>Expression</b></td>
2176 <td width="82%"><b>Value</b></td>
2179 <td width="18%" bgcolor="#FFFFFF"><code>
2180 runtime_error::what()</code></td>
2181 <td width="82%" bgcolor="#FFFFFF">
2182 <code><i>what_arg</i>.c_str()</code></td>
2185 <td width="18%"><code>code()</code></td>
2186 <td width="82%"><code>ec</code></td>
2189 <td width="18%"><code>path1().empty()</code></td>
2190 <td width="82%"><code>true</code></td>
2193 <td width="18%"><code>path2().empty()</code></td>
2194 <td width="82%"><code>true</code></td>
2198 <pre><a name="filesystem_error-3-arg">filesystem_error</a>(const std::string& what_arg, const path& p1, error_code ec);</pre>
2200 <p><i>Postcondition:</i></p>
2201 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="46%">
2203 <td width="18%"><b>Expression</b></td>
2204 <td width="82%"><b>Value</b></td>
2207 <td width="18%" valign="top"><code>
2208 runtime_error::what()</code></td>
2210 <code><i>what_arg</i>.c_str()</code></td>
2213 <td width="18%" valign="top"><code>code()</code></td>
2214 <td width="82%"><code>ec</code></td>
2217 <td width="18%" valign="top"><code>path1()</code></td>
2218 <td width="82%">Reference to stored copy of <code>p1</code></td>
2221 <td width="18%" valign="top"><code>path2().empty()</code></td>
2222 <td width="82%"><code>true</code></td>
2226 <pre><a name="filesystem_error-4-arg">filesystem_error</a>(const std::string& what_arg, const path& p1, const path& p2, error_code ec);</pre>
2228 <p><i>Postcondition:</i></p>
2229 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="46%">
2231 <td width="18%"><b>Expression</b></td>
2232 <td width="82%"><b>Value</b></td>
2235 <td width="18%"><code>
2236 runtime_error::what()</code></td>
2239 <code><i>w</i></code></u><code><i>hat_arg</i>.c_str()</code></td>
2242 <td width="18%"><code>code()</code></td>
2243 <td width="82%"><code>ec</code></td>
2246 <td width="18%"><code>path1()</code></td>
2247 <td width="82%">Reference to stored copy of <code>p1</code></td>
2250 <td width="18%"><code>path2()</code></td>
2251 <td width="82%">Reference to stored copy of <code>p2</code></td>
2255 <pre>const path& <a name="filesystem_error-path1">path1</a>() const;</pre>
2257 <p><i>Returns:</i> Reference to copy of <code>p1</code> stored by the
2258 constructor, or, if none, an empty path.</p>
2260 <pre>const path& <a name="filesystem_error-path2">path2</a>() const;</pre>
2262 <p><i>Returns:</i> Reference to copy of <code>p2</code> stored by the
2263 constructor, or, if none, an empty path.</p>
2265 <pre>const char* <a name="filesystem_error-what">what</a>() const;</pre>
2267 <p><i>Returns: </i>A string containing <code>runtime_error::what()</code>. The exact format is unspecified.
2268 Implementations are encouraged but not required to include <code>path1.native_string()</code>if not empty, <code>path2.native_string()</code>if
2269 not empty, and <code>system_error::what()</code> strings in the returned
2272 <h2><a name="Enum-file_type">Enum file_type</a> [enum.file_type]</h2>
2273 <p>This enum specifies constants uses to identify file types.</p>
2274 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
2276 <td><b>Constant Name</b></td>
2277 <td><b>Meaning</b></td>
2280 <td><code>status_error</code></td>
2281 <td>An error occurred while trying to obtain the status of the file. The
2282 file simply not being found is <b><u>not</u></b> considered a status error. </td>
2285 <td><code>file_not_found</code></td>
2286 <td>The file could not be found</td>
2289 <td><code>regular_file</code></td>
2290 <td>Regular file</td>
2293 <td><code>directory_file</code></td>
2294 <td>Directory file</td>
2297 <td><code>symlink_file</code></td>
2298 <td>Symbolic link file</td>
2301 <td><code>block_file</code></td>
2302 <td>Block special file</td>
2305 <td><code>character_file</code></td>
2306 <td>Character special file</td>
2309 <td><code>fifo_file</code></td>
2310 <td>FIFO or pipe file</td>
2313 <td><code>socket_file</code></td>
2314 <td>Socket file</td>
2317 <td><code>type_unknown</code></td>
2318 <td>The file exists, but it is of a system specific type not covered by any
2319 of the above cases.</td>
2322 <h2><a name="Enum-perms">Enum perms</a> [enum.perms]</h2>
2323 <p>This <code>enum</code> specifies bitmask constants uses to identify file
2324 permissions. <i><span style="background-color: #E0E0E0">ISO/</span><span style="background-color: #E0E0E0">IEC</span><span style="background-color: #E0E0E0"> 9945
2325 (POSIX) specifies actual values, and those values have been adopted here because
2326 they are very familiar and ingrained for many POSIX
2327 users.</span></i></p>
2329 <p><span style="background-color: #FFFF00">Windows: All permissions except write are currently ignored. There is only a
2330 single write permission; setting write permission for owner, group, or others
2331 sets write permission for all, and removing write permission for owner, group,
2332 or others removes write permission for all. </span> </p>
2334 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
2336 <td><b>Name</b></td>
2337 <td align="center"><b>Value<br>
2339 <td align="center"><b>ISO/IEC 9945<br>
2341 <td><b>Definition or notes</b></td>
2345 <p><code>no_perms</code></td><td><code>0</code></td><td></td>
2346 <td>There are no permissions set for the file. Note: <code>file_not_found</code> is <code>no_perms</code> rather than <code>perms_not_known</code></td>
2348 <tr><td><code>owner_read</code></td><td><code>0400</code></td><td> <code>S_IRUSR</code></td>
2349 <td> Read permission, owner</td>
2351 <tr><td><code>owner_write</code></td><td><code>0200</code></td><td> <code>S_IWUSR</code></td>
2352 <td> Write permission, owner</td>
2354 <tr><td><code>owner_exe</code></td><td><code>0100</code></td><td> <code>S_IXUSR</code></td>
2355 <td> Execute/search permission, owner</td>
2357 <tr><td><code>owner_all</code></td><td><code>0700</code></td><td> <code>S_IRWXU</code></td>
2358 <td> Read, write, execute/search by owner; <code>owner_read | owner_write | owner_exe</code></td>
2360 <tr><td><code>group_read</code></td><td><code>040</code></td><td> <code>S_IRGRP</code></td>
2361 <td> Read permission, group</td>
2363 <tr><td><code>group_write</code></td><td><code>020</code></td><td> <code>S_IWGRP</code></td>
2364 <td> Write permission, group</td>
2366 <tr><td><code>group_exe</code></td><td><code>010</code></td><td> <code>S_IXGRP</code></td>
2367 <td> Execute/search permission, group</td>
2369 <tr><td><code>group_all</code></td><td><code>070</code></td><td> <code>S_IRWXG</code></td>
2370 <td> Read, write, execute/search by group; <code>group_read | group_write | group_exe</code></td>
2372 <tr><td><code>others_read</code></td><td><code>04</code></td><td> <code>S_IROTH</code></td>
2373 <td> Read permission, others</td>
2375 <tr><td><code>others_write</code></td><td><code>02</code></td><td> <code>S_IWOTH</code></td>
2376 <td> Write permission, others</td>
2378 <tr><td><code>others_exe</code></td><td><code>01</code></td><td> <code>S_IXOTH</code></td>
2379 <td> Execute/search permission, others</td>
2381 <tr><td><code>others_all</code></td><td><code>07</code></td><td> <code>S_IRWXO</code></td>
2382 <td>Read, write, execute/search by others; <code>others_read | others_write | others_exe</code></td>
2384 <tr><td><code>all_all</code></td><td><code>0777</code></td><td> </td><td><code>owner_all | group_all | others_all</code></td>
2386 <tr><td><code>set_uid_on_exe</code></td><td><code>04000</code></td><td> <code>S_ISUID</code></td>
2387 <td> Set-user-ID on execution</td>
2389 <tr><td><code>set_gid_on_exe</code></td><td><code>02000</code></td><td> <code>S_ISGID</code></td>
2390 <td> Set-group-ID on execution</td>
2392 <tr><td><code><a name="sticky_bit">sticky_bit</a> </code></td><td><code>01000</code></td><td> <code>S_ISVTX</code></td>
2393 <td> Operating system dependent. Inherently non-portable, even between ISO/IEC 9945
2394 operating systems.</td>
2396 <tr><td><code><a name="perms_mask">perms_mask</a></code></td><td><code>07777</code></td><td> </td>
2397 <td><code>all_all | set_uid_on_exe | set_gid_on_exe | sticky_bit</code></td>
2399 <tr><td><code>perms_not_known</code></td><td><code>0xFFFF</code></td><td></td><td>
2400 The permissions are not known, such as when a <code>file_status</code> object
2401 is created without specifying the permissions</td>
2404 <p><code>add_perms</code></td><td><code>0x1000</code></td><td></td><td>
2405 <p><code>permissions()</code> adds the argument permission bits to the
2406 file's current bits</td>
2408 <tr><td><code>remove_perms</code></td><td><code>0x2000</code></td><td></td><td>
2409 <code>permissions()</code> removes the argument permission bits from the
2410 file's current bits</td>
2412 <tr><td><code><a name="symlink_perms">symlink_perms</a></code></td><td><code>0x4000</code></td><td></td><td>
2413 <span style="background-color: #FFFF00">On ISO/</span><span style="background-color: #FFFF00">IEC</span><span style="background-color: #FFFF00"> 9945
2414 </span> <code><span style="background-color: #FFFF00">permissions()</span></code><span style="background-color: #FFFF00"> resolves symlinks unless
2415 </span> <code><span style="background-color: #FFFF00">symlink_perms</span></code><span style="background-color: #FFFF00"> is specified.
2416 Meaningless on Windows as </span> <code>
2417 <span style="background-color: #FFFF00">permissions()</span></code><span style="background-color: #FFFF00"> never resolves symlinks.
2418 Meaningless on Mac OS X and some other BSD systems as </span> <code>
2419 <span style="background-color: #FFFF00">permissions()</span></code><span style="background-color: #FFFF00"> always resolves symlinks. Get over it.</span></td>
2423 <h2><a name="file_status">Class file_status</a> [class.file_status]</h2>
2424 <pre>namespace boost
2426 namespace filesystem
2432 // <a href="#file_status-constructors">constructors</a>
2433 file_status() noexcept;
2434 explicit file_status(<a href="#file_type">file_type</a> ft, <a href="#Enum-perms">perms</a> prms = perms_not_known) noexcept;
2436 // compiler generated
2437 file_status(const file_status&) noexcept;
2438 file_status& operator=(const file_status&) noexcept;
2439 ~file_status() noexcept;
2441 // <a href="#file_status-observers">observers</a>
2442 <a href="#file_type">file_type</a> type() const noexcept;
2443 <a href="#Enum-perms">perms</a> permissions() const noexcept;
2445 // <a href="#file_status-modifiers">modifiers</a>
2446 void type(<a href="#file_type">file_type</a> ft) noexcept;
2447 void permissions(<a href="#Enum-perms">perms</a> prms) noexcept;
2449 } // namespace filesystem
2450 } // namespace boost</pre>
2451 <p>An object of type <code>file_status</code> stores information about the type
2452 and permissions of a file.</p>
2453 <h3><a name="file_status-constructors"><code>file_status</code> constructors</a>
2454 [file_status.cons]</h3>
2455 <pre>explicit file_status() noexcept;</pre>
2457 <p><i>Postconditions:</i> <code>type() == status_error</code>, <code>permissions() == perms_not_known</code>.</p>
2459 <pre>explicit file_status(<a href="#file_type">file_type</a> ft, <a href="#Enum-perms">perms</a> prms = perms_not_known) noexcept;</pre>
2461 <p><i>Postconditions:</i> <code>type() == ft</code>, <code>permissions() == prms</code>.</p>
2463 <h3><a name="file_status-observers"><code>file_status</code> observers</a> [file_status.obs]</h3>
2464 <pre><a href="#file_type">file_type</a> type() const noexcept;</pre>
2466 <p><i>Returns: </i>The value of <code>type()</code> specified by the <i>postconditions</i> of the most recent call to a constructor, operator=, or <code>type(file_type)</code> function.</p>
2468 <pre><a href="#Enum-perms">perms</a> permissions() const noexcept;</pre>
2470 <p><i>Returns: </i>The value of <code>permissions()</code> specified by the <i>postconditions</i> of the most recent call to a constructor, operator=, or <code>permissions(perms)</code> function.</p>
2472 <h3><a name="file_status-modifiers"><code>file_status</code> modifiers</a> [file_status.mods]</h3>
2473 <pre>void type(<a href="#file_type">file_type</a> ft) noexcept;</pre>
2475 <p><i>Postconditions:</i> <code>type() == ft</code>.</p>
2477 <pre>void permissions(<a href="#Enum-perms">perms</a> prms) noexcept;</pre>
2479 <p><i>Postconditions:</i> <code>permissions() == prms</code>.</p>
2481 <h2><a name="Class-directory_entry">Class <code>directory_entry</code></a> [class.directory_entry]</h2>
2483 <pre>namespace boost
2485 namespace filesystem
2487 class directory_entry
2491 // <a href="#directory_entry-constructors">constructors</a> and destructor
2493 directory_entry(const directory_entry&);
2494 explicit directory_entry(const path& p, file_status st=file_status(),
2495 file_status symlink_st=file_status());
2498 // <a href="#directory_entry-modifiers">modifiers</a>
2499 directory_entry& operator=(const directory_entry&);
2500 void assign(const path& p, file_status st=file_status(),
2501 file_status symlink_st=file_status());
2502 void replace_filename(const path& p, file_status st=file_status(),
2503 file_status symlink_st=file_status());
2505 // <a href="#directory_entry-observers">observers</a>
2506 const path& path() const;
2507 file_status status() const;
2508 file_status status(system::error_code& ec) const;
2509 file_status symlink_status() const;
2510 file_status symlink_status(system::error_code& ec) const;
2512 bool operator< (const directory_entry& rhs);
2513 bool operator==(const directory_entry& rhs);
2514 bool operator!=(const directory_entry& rhs);
2515 bool operator< (const directory_entry& rhs);
2516 bool operator<=(const directory_entry& rhs);
2517 bool operator> (const directory_entry& rhs);
2518 bool operator>=(const directory_entry& rhs);
2520 path m_path; // for exposition only
2521 mutable file_status m_status; // for exposition only; stat()-like
2522 mutable file_status m_symlink_status; // for exposition only; lstat()-like
2525 } // namespace filesystem
2526 } // namespace boost</pre>
2528 <p>A <code>directory_entry</code> object stores a <code>path object</code>,
2529 a <code>file_status</code> object for non-symbolic link status, and a <code>file_status</code> object for symbolic link status. The <code>file_status</code> objects act as value caches.</p>
2531 <p>[<i>Note:</i> Because <code>status()</code>on a pathname may be a relatively expensive operation,
2532 some operating systems provide status information as a byproduct of directory
2533 iteration. Caching such status information can result is significant time savings. Cached and
2534 non-cached results may differ in the presence of file system races. <i>—end note</i>]</p>
2535 <p><span style="background-color: #E0E0E0"><i>Actual cold-boot timing of iteration over
2536 a directory with 15,047 entries was six seconds for non-cached status queries
2537 versus one second for cached status queries. Windows XP, 3.0 GHz processor, with
2538 a moderately fast hard-drive. Similar speedups are expected on Linux and BSD-derived
2539 systems that provide status as a by-product of directory iteration.</i></span></p>
2541 <h3> <a name="directory_entry-constructors"> <code>directory_entry </code>constructors</a>
2542 [directory_entry.cons]</h3>
2543 <pre>directory_entry();</pre>
2545 <p><i>Postcondition:</i></p>
2546 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="36%">
2548 <td width="18%"><b>Expression</b></td>
2549 <td width="82%"><b>Value</b></td>
2552 <td width="18%"><code>path().empty()</code></td>
2553 <td width="82%"><code>true</code></td>
2556 <td width="18%"><code>status()</code></td>
2557 <td width="82%"><code>file_status()</code></td>
2560 <td width="18%"><code>symlink_status()</code></td>
2561 <td width="82%"><code>file_status()</code></td>
2565 <pre>explicit directory_entry(const path& p, file_status st=file_status(), file_status symlink_st=file_status());</pre>
2567 <p><i>Postcondition:</i></p>
2568 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="36%">
2570 <td width="18%"><b>Expression</b></td>
2571 <td width="82%"><b>Value</b></td>
2574 <td width="18%"><code>path()</code></td>
2575 <td width="82%"><code>p</code></td>
2578 <td width="18%"><code>status()</code></td>
2579 <td width="82%"><code>st</code></td>
2582 <td width="18%"><code>symlink_status()</code></td>
2583 <td width="82%"><code>symlink_st</code></td>
2587 <h3> <a name="directory_entry-modifiers"> <code>directory_entry </code>modifiers</a>
2588 [directory_entry.mods]</h3>
2589 <pre>void assign(const path& p, file_status st=file_status(), file_status symlink_st=file_status());</pre>
2591 <p><i>Postcondition:</i></p>
2592 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="36%">
2594 <td width="18%"><b>Expression</b></td>
2595 <td width="82%"><b>Value</b></td>
2598 <td width="18%"><code>path()</code></td>
2599 <td width="82%"><code>p</code></td>
2602 <td width="18%"><code>status()</code></td>
2603 <td width="82%"><code>st</code></td>
2606 <td width="18%"><code>symlink_status()</code></td>
2607 <td width="82%"><code>symlink_st</code></td>
2611 <pre>void replace_filename(const path& p, file_status st=file_status(), file_status symlink_st=file_status());</pre>
2613 <p><i>Postcondition:</i></p>
2614 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="43%">
2616 <td width="18%"><b>Expression</b></td>
2617 <td width="82%"><b>Value</b></td>
2620 <td width="18%"><code>path()</code></td>
2621 <td width="82%"><code>path().branch() / s</code></td>
2624 <td width="18%"><code>status()</code></td>
2625 <td width="82%"><code>st</code></td>
2628 <td width="18%"><code>symlink_status()</code></td>
2629 <td width="82%"><code>symlink_st</code></td>
2633 <h3> <a name="directory_entry-observers"> <code>directory_entry</code> observers</a>
2634 [directory_entry.obs]</h3>
2635 <pre>const path& path() const;</pre>
2637 <p><i>Returns:</i> <code>m_path</code></p>
2639 <pre>file_status status() const;
2640 file_status status(system::error_code& ec) const;</pre>
2642 <p><i>Effects:</i> As if,</p>
2644 <pre>if ( !status_known( m_status ) )
2646 if ( status_known(m_symlink_status) && !is_symlink(m_symlink_status) )
2647 { m_status = m_symlink_status; }
2648 else { m_status = status(m_path<i>[, ec]</i>); }
2651 <p><i>Returns:</i> <code>m_status</code></p>
2653 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
2656 <pre>file_status symlink_status() const;
2657 file_status symlink_status(system::error_code& ec) const;</pre>
2660 <i>Effects:</i> As if,</p>
2662 <pre>if ( !status_known( m_symlink_status ) )
2664 m_symlink_status = symlink_status(m_path<i>[, ec]</i>);
2667 <p><i>Returns:</i> <code>m_symlink_status</code></p>
2669 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
2672 <pre>bool operator==(const directory_entry& rhs);</pre>
2674 <p><i>Returns:</i> <code>m_path == rhs.m_path</code>.</p>
2676 <pre>bool operator!=(const directory_entry& rhs);</pre>
2678 <p><i>Returns:</i> <code>m_path != rhs.m_path</code>.</p>
2680 <pre>bool operator< (const directory_entry& rhs);</pre>
2682 <p><i>Returns:</i> <code>m_path < rhs.m_path</code>.</p>
2684 <pre>bool operator<=(const directory_entry& rhs);</pre>
2686 <p><i>Returns:</i> <code>m_path <= rhs.m_path</code>.</p>
2688 <pre>bool operator> (const directory_entry& rhs);</pre>
2690 <p><i>Returns:</i> <code>m_path > rhs.m_path</code>.</p>
2692 <pre>bool operator>=(const directory_entry& rhs);</pre>
2694 <p><i>Returns:</i> <code>m_path >= rhs.m_path</code>.</p>
2696 <h2><a name="Class-directory_iterator">Class <code>directory_iterator</code>
2697 [class.directory_iterator]</a></h2>
2698 <p>Objects of type <code>directory_iterator</code> provide standard library
2699 compliant iteration over the contents of a directory. Also see class <code><a href="#Class-recursive_directory_iterator">recursive_directory_iterator</a></code>.</p>
2700 <pre>namespace boost
2702 namespace filesystem
2704 class directory_iterator
2707 // <a href="#directory_iterator-members">member functions</a>
2709 directory_iterator() noexcept; // creates the "end" iterator
2710 directory_iterator(const directory_iterator&);
2711 explicit directory_iterator(const path& p, <a href="#directory_options">directory_options</a> opts = directory_options::none);
2712 directory_iterator(const path& p, system::error_code& ec);
2713 directory_iterator(const path& p, <a href="#directory_options">directory_options</a> opts, system::error_code& ec);
2714 ~directory_iterator();
2716 directory_iterator& operator=(const directory_iterator&);
2718 directory_iterator& operator++();
2719 directory_iterator& increment(system::error_code& ec);
2721 // other members as required by
2722 // C++ Std, 24.1.1 Input iterators [input.iterators]
2725 } // namespace filesystem
2726 } // namespace boost</pre>
2727 <p> <code>directory_iterator</code> satisfies the requirements of an
2728 input iterator (C++ Std, 24.2.1, Input iterators [input.iterators]).</p>
2729 <p>A <code>directory_iterator</code> reads successive elements from the directory for
2730 which it was constructed, as if by calling ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/readdir_r.html">readdir() or readdir_r()</a></code>. After a <code>directory_iterator</code> is constructed, and every time <code>operator++</code> is called,
2731 it reads a directory element and stores information about it in an object of type <code><a href="#Class-directory_entry">directory_entry</a></code>. <code>operator++</code> is not equality preserving; that is, <code>i == j</code> does not imply that <code>++i == ++j</code>. </p>
2733 <p>[<i>Note:</i> The practical consequence of not preserving equality is that directory iterators
2734 can only be used for single-pass algorithms. <i>—end note</i>]</p>
2736 <p>If the end of the directory elements is reached, the iterator shall become equal to
2737 the end iterator value. The constructor <code>directory_iterator()</code> with no arguments always constructs an end iterator object, which
2738 shall be the only valid iterator for the end condition. The result of <code>operator*</code> on an end iterator is not defined. For any other iterator value
2739 a <code>const directory_entry&</code> is returned. The result of <code>operator-></code> on an end iterator is
2740 undefined behavior. For any other iterator value a <code>const directory_entry*</code> is
2742 <p>Two end iterators are always equal. An end iterator shall not be equal to a non-end
2745 <p><i><span style="background-color: #E0E0E0">The above wording is based on the
2746 Standard Library's istream_iterator wording.</span></i></p>
2748 <p>The result of calling the <code>path()</code> member of the <code>directory_entry</code> object obtained by dereferencing a <code>directory_iterator</code> is a reference to a <code>path</code> object composed of the directory argument from which the iterator was
2749 constructed with filename of the directory entry appended as if by <code>operator/=</code>. </p>
2750 <p>Directory iteration shall not yield directory entries for the current (<i>dot</i>)
2751 and parent (<i>dot dot</i>) directories.</p>
2752 <p>The order of directory entries obtained by dereferencing successive
2753 increments of a <code>directory_iterator</code> is unspecified.</p>
2755 <p>[<i>Note:</i> Programs performing directory iteration may wish to test if the
2756 path obtained by dereferencing a directory iterator actually exists. It could be
2758 symbolic link to a non-existent file. Programs recursively
2759 walking directory trees for purposes of removing and renaming entries may wish
2760 to avoid following symbolic links.</p>
2761 <p>If a file is removed from or added to a directory after the
2762 construction of a <code>directory_iterator</code> for the directory, it is
2763 unspecified whether or not subsequent incrementing of the iterator will ever
2764 result in an iterator whose value is the removed or added directory entry. See
2765 ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/readdir_r.html">readdir_r()</a></code>. <i>—end note</i>]</p>
2767 <h3><a name="directory_iterator-members"><code>directory_iterator</code> members</a>
2768 [directory_iterator.members]</h3>
2770 <p><code><a name="directory_iterator-default-ctor">directory_iterator</a>()
2771 noexcept;</code></p>
2775 <p><i>Effects:</i> Constructs the end iterator.</p>
2779 <pre><code>explicit <a name="directory_iterator-ctor-path">directory_iterator</a>(</code>const path& p, <a href="#directory_options">directory_options</a> opts = directory_options::none<code>);
2780 directory_iterator(</code>const path& p, system::error_code& ec<code>);
2781 directory_iterator(</code>const path& p, <a href="#directory_options">directory_options</a> opts, system::error_code& ec<code>);</code></pre>
2784 <p><i>Effects:</i> Constructs an iterator representing the first
2785 entry in the directory <code>p</code> resolves to, if any; otherwise, the end iterator.
2786 If opening the directory fails with a <code>permission_denied</code> error and <code>(opts & directory_options::skip_permission_denied) != 0</code>,
2787 constructs the end iterator and ignores the error (the operation completes successfully). If <code>opts</code> is not specified, it is assumed to be <code>directory_options::none</code>.</p>
2789 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
2791 <p>[<i>Note:</i> To iterate over the current directory, use <code>directory_iterator(".")</code> rather than <code>directory_iterator("")</code>. <i>—end note</i>]</p>
2793 <pre>directory_iterator& <a name="directory_iterator-increment">operator++</a>();
2794 directory_iterator& increment(system::error_code& ec);</pre>
2797 <p><i>Effects:</i> As specified by the C++ Standard, 24.1.1 Input iterators [input.iterators]. In case of error the iterator is left in the end state.</p>
2799 <p><i>Returns:</i> <code>*this</code>.</p>
2801 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
2804 <h3><a name="directory_iterator-non-member-functions"><code>directory_iterator</code> non-member functions</a></h3>
2805 <pre>const directory_iterator& begin(const directory_iterator& iter);</pre>
2807 <p><i>Returns: </i><code>iter</code>.</p>
2809 <pre>directory_iterator end(const directory_iterator&);</pre>
2811 <p><i>Returns: </i><code>directory_iterator()</code>.</p>
2813 <h2><a name="Class-recursive_directory_iterator">Class <code>recursive_directory_iterator</code>
2814 [class.rec.dir.itr]</a></h2>
2815 <p>Objects of type <code>recursive_directory_iterator</code> provide standard library
2816 compliant iteration over the contents of a directory, including recursion into
2817 its sub-directories.</p>
2818 <pre>namespace boost
2820 namespace filesystem
2822 class recursive_directory_iterator :
2823 public iterator<input_iterator_tag, directory_entry>
2827 // constructors and destructor
2828 recursive_directory_iterator() noexcept;
2829 recursive_directory_iterator(const recursive_directory_iterator&);
2830 explicit recursive_directory_iterator(const path& p,
2831 <a href="#directory_options">directory_options</a> opts = directory_options::none);
2832 recursive_directory_iterator(const path& p,
2833 <a href="#directory_options">directory_options</a> opts, system::error_code& ec);
2834 // deprecated constructors, use overloads accepting directory_options instead
2835 explicit recursive_directory_iterator(const path& p,
2836 <a href="#symlink_option">symlink_option</a> opts = symlink_option::none);
2837 recursive_directory_iterator(const path& p,
2838 <a href="#symlink_option">symlink_option</a> opts, system::error_code& ec);
2839 recursive_directory_iterator(const path& p, system::error_code& ec);
2840 ~recursive_directory_iterator();
2843 int depth() const noexcept;
2844 bool recursion_pending() const noexcept;
2846 // deprecated observers
2847 int level() const noexcept;
2848 bool no_push_pending() const noexcept;
2851 recursive_directory_iterator& operator=(const recursive_directory_iterator&);
2853 recursive_directory_iterator& operator++();
2854 recursive_directory_iterator& increment(system::error_code& ec);
2857 void pop(system::error_code& ec);
2858 void disable_recursion_pending(bool value = true) noexcept;
2860 // deprecated modifiers
2861 void no_push(bool value = true);
2863 // other members as required by
2864 // C++ Std, Input iterators [input.iterators]
2867 <i><b> // actual data members will probably be stored in a shared object,
2868 // or some similar mechanism, to achieve the required input iterator
2869 // copy semantics</b></i>
2870 int m_depth; <b><i>// for exposition only</i></b>
2871 bool m_recursion_pending; <i><b>// for exposition only</b></i>
2872 <a href="#directory_options">directory_options</a> m_options; <i><b>// for exposition only</b></i>
2875 } // namespace filesystem
2876 } // namespace boost</pre>
2878 <p>The behavior of a <code>recursive_directory_iterator</code> is the same
2879 as a <code>directory_iterator</code> unless otherwise specified.</p>
2881 <li>Incrementing a <code>recursive_directory_iterator</code> pointing to a
2882 directory causes that directory itself to be iterated over, as specified by
2883 the <code>operator++</code> and <code>increment</code> functions.<br>
2885 <li>When a <code>recursive_directory_iterator</code> reaches the end of the directory currently being iterated
2886 over, or when <code>pop()</code> is called, <code>m_depth</code> is
2887 decremented, and iteration of the parent directory continues.</li>
2889 <pre>recursive_directory_iterator() noexcept;</pre>
2892 <p><i>Effects:</i> Constructs the end iterator.</p>
2896 <pre>explicit recursive_directory_iterator(const path& p, <a href="#directory_options">directory_options</a> opts = directory_options::none);
2897 recursive_directory_iterator(const path& p, <a href="#directory_options">directory_options</a> opts, system::error_code& ec);
2898 explicit recursive_directory_iterator(const path& p, <a href="#symlink_option">symlink_option</a> opts = symlink_option::none);
2899 recursive_directory_iterator(const path& p, <a href="#symlink_option">symlink_option</a> opts, system::error_code& ec);
2900 recursive_<code>directory_iterator(</code>const path& p, system::error_code& ec<code>);</code></pre>
2903 <p><i>Effects:</i> Constructs an iterator representing the first
2904 entry in the directory <code>p</code> resolves to, if any; otherwise, the end iterator.</p>
2906 <p><i>Postcondition: </i>Unless the end iterator was constructed,<i> </i><code>depth() == 0 && recursion_pending() == true && m_options == opts</code>.
2907 For the signature without the <code>opts</code> argument, <code>opts</code> is assumed to be <code>directory_options::none</code>.</p>
2909 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
2911 <p>[<i>Note:</i> To iterate over the current directory, use <code>recursive_directory_iterator(".")</code> rather than <code>recursive_directory_iterator("")</code>. <i>—end note</i>]</p>
2913 <p>[<i>Note:</i> By default, <code>recursive_directory_iterator</code> does not
2914 follow directory symlinks. To follow directory symlinks, specify <code>directory_options::follow_directory_symlink</code> in <code>opts</code>. <i>—end note</i>]</p>
2916 <pre>int depth() const noexcept;
2917 int level() const noexcept;</pre>
2919 <p><i>Requires:</i> <code>*this != recursive_directory_iterator()</code>.</p>
2920 <p><i>Returns:</i> <code>m_depth</code>.</p>
2922 <pre>bool recursion_pending() const noexcept;</pre>
2924 <p><i>Requires:</i> <code>*this != recursive_directory_iterator()</code>.</p>
2925 <p><i>Returns:</i> <code>m_recursion_pending</code>.</p>
2927 <pre>bool no_push_pending() const noexcept;</pre>
2929 <p><i>Requires:</i> <code>*this != recursive_directory_iterator()</code>.</p>
2930 <p><i>Returns:</i> <code>!recursion_pending()</code>.</p>
2932 <pre><code>recursive_directory_iterator</code>& <a name="recursive_directory_iterator-increment">operator++</a>();
2933 recursive_directory_iterator& increment(system::error_code& ec);</pre>
2936 <p><i>Effects:</i> As specified by the C++ Standard, 24.1.1 Input iterators [input.iterators],
2942 <p>if <code>recursion_pending() && is_directory(this->status())
2943 && (!is_symlink(this->symlink_status()) || (m_options & directory_options::follow_directory_symlink) != 0)</code> then:
2946 <p>directory <code>(*this)->path()</code> is opened and recursively iterated into and <code>m_depth</code> is incremented;</p>
2949 <p>if opening the directory fails with a <code>permission_denied</code> error and <code>(m_options & directory_options::skip_permission_denied) != 0</code>,
2950 increment the iterator on the current level and ignore the error (the operation completes successfully).</p>
2956 <li>if there are no more directory entries at this level then <code>m_depth</code>
2957 is decremented and iteration of the parent directory resumes.</li>
2960 <p>If the operation completes with an error, then
2962 <li>if <code>(m_options & directory_options::pop_on_error) != 0</code>, the iterator is left in a state as if after repeatedly calling <code>pop()</code> until it succeeds or the iterator becomes equal to an end iterator; any <code>pop()</code> failures are not reported to the caller;</li>
2963 <li>otherwise, the iterator is left equal to an end iterator.</li>
2967 <p><i>Postcondition:</i> <code>recursion_pending() == true</code>.</p>
2969 <p><i>Returns:</i> <code>*this</code>.</p>
2971 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
2975 void pop(system::error_code& ec);</pre>
2977 <p><i>Requires:</i> <code>*this != recursive_directory_iterator()</code>.</p>
2978 <p><i>Effects:</i> If <code>depth() == 0</code>, set <code>*this</code> to <code>recursive_directory_iterator()</code>.
2979 Otherwise, <code>--m_depth</code>, cease iteration of the directory currently being
2980 iterated over, and continue iteration over the parent directory.</p>
2981 <p>If the operation completes with an error, then
2983 <li>if <code>(m_options & directory_options::pop_on_error) != 0</code>, the iterator is left in a state as if after repeatedly calling <code>pop()</code> until it succeeds or the iterator becomes equal to an end iterator; any <code>pop()</code> failures are not reported to the caller;</li>
2984 <li>otherwise, the iterator is left equal to an end iterator.</li>
2988 <pre>void disable_recursion_pending(bool value = true) noexcept;
2989 void no_push(bool value = true) noexcept;</pre>
2991 <p><i>Requires:</i> <code>*this != recursive_directory_iterator()</code>.</p>
2992 <p><i>Postcondition:</i> <code>recursion_pending() == !value</code>.</p>
2993 <p>[<i>Note:</i> These functions are used to prevent
2994 unwanted recursion into a directory. <i>—end note</i>]</p>
2996 <h3><a name="recursive_directory_iterator-non-member-functions"><code>recursive_directory_iterator</code> non-member functions</a></h3>
2997 <pre>const recursive_directory_iterator& begin(const recursive_directory_iterator& iter);</pre>
2999 <p><i>Returns: </i><code>iter</code>.</p>
3001 <pre>recursive_directory_iterator end(const recursive_directory_iterator&);</pre>
3003 <p><i>Returns: </i><code>recursive_directory_iterator()</code>.</p>
3005 <h2><a name="Operational-functions">Operational functions</a> [fs.op.funcs]</h2>
3006 <p>Operational functions query or modify files, including directories, in external
3008 <p>Operational functions access a file by resolving an
3009 object of class <code>path</code> to a particular file in a file hierarchy. The
3010 path is resolved as if by the ISO/IEC 9945 <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap04.html#tag_04_11">Pathname Resolution</a> mechanism.</p>
3011 <p>[<i>Note: </i>Because hardware failures, network failures, <a href="#file-system-race">file system races</a>, and many
3012 other kinds of errors occur frequently in file system operations, users should be aware
3013 that any filesystem operational function, no matter how apparently innocuous, may encounter
3014 an error. See <a href="#Error-reporting">Error reporting</a>. <i>—end note</i>]</p>
3015 <pre>path <a name="absolute">absolute</a>(const path& p, const path& base=current_path());</pre>
3017 <p><i>Returns:</i> A <a href="#Absolute-path">absolute path</a> composed according to the
3019 <table border="1" cellpadding="5" cellspacing="0" bordercolor="#111111" style="border-collapse: collapse">
3021 <td align="center"> </td>
3022 <td align="center"><b><code>p.<br>
3023 has_root_directory()</code></b></td>
3024 <td align="center"><b><code>!p.has_root_directory()</code></b></td>
3027 <td align="center"><b><code>p.has_root_name()</code></b></td>
3028 <td align="left"><code>return p</code></td>
3029 <td align="left"><code>return<br>
3030 p.root_name()<br>
3031 / absolute(base)<br>
3032 .root_directory()<br>
3033 / absolute(base)<br>
3034 .relative_path()<br>
3035 / p.relative_path()</code></td>
3038 <td align="center"><b><code>!p.has_root_name()</code></b></td>
3039 <td align="left"><code>return<br>
3040 absolute(base)<br>
3041 .root_name()<br>
3042 / p</code></td>
3043 <td align="left"><code>return absolute(base)<br>
3044 / p</code></td>
3047 <p>[<i>Note:</i> For the returned path, <code>rp,</code> <code>rp.is_absolute()</code> is true. <i>—end note</i>]</p>
3048 <p><i>Throws:</i> If <code>base.is_absolute()</code> is true, throws only if
3049 memory allocation fails.</p>
3051 <pre>path <a name="canonical">canonical</a>(const path& p, const path& base = current_path());
3052 path canonical(const path& p, system::error_code& ec);
3053 path canonical(const path& p, const path& base, system::error_code& ec);</pre>
3055 <p><i>Overview:</i> Converts <code>p</code>, which must exist, to an absolute
3056 path that has no symbolic link, <a href="#Dot">dot</a>,
3057 or <a href="#Dot">dot-dot</a> elements. </p>
3058 <p><i>Returns:</i> A <a href="#canonical-path">canonical path</a> that refers to
3059 the same file system object as <code>absolute(p,base)</code>. For the overload
3060 without a <code>base</code> argument, <code>base</code> is <code>current_path()</code>.</p>
3061 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3063 <p><i>Remarks:</i> <code>!exists(p)</code> is an error.</p>
3065 <p>[<i>Note:</i> Canonical pathnames allow security checking of a path (eg.
3066 does this path live in /home/goodguy or /home/badguy?) —end note]</p>
3069 <pre>void <a name="copy">copy</a>(const path& from, const path& to);
3070 void copy(const path& from, const path& to, system::error_code& ec);</pre>
3072 <p><i>Effects:</i> As if</p>
3075 <pre>file_status s(symlink_status(from<i>[</i><code>, ec</code><i>]</i>));
3077 copy_symlink(from, to<i>[</i><code>, ec</code><i>]</i>);
3078 else if(is_directory(s))
3079 copy_directory(from, to<i>[</i><code>, ec</code><i>]</i>);
3080 else if(is_regular_file(s))
3081 copy_file(from, to, copy_option::fail_if_exists<i>[</i><code>, ec</code><i>]</i>);
3083 <i> Report error as specified in <a href="#Error-reporting">Error reporting</a>.</i></pre>
3085 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3088 <pre>void <a name="copy_directory">copy_directory</a>(const path& from, const path& to);
3089 void copy_directory(const path& from, const path& to, system::error_code& ec);</pre>
3091 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
3092 bordercolor="#111111" width="90%" bgcolor="#E0E0E0">
3095 <p><i>This function is poorly named; it should probably be an overload of
3096 <code>create_directory</code> with an additional argument.</i></td>
3100 <p><i>Effects: </i>Creates directory <code>to</code>, with
3101 attributes copied from directory <code>from</code>. The set of attributes
3102 copied is operating system dependent.</p>
3105 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
3106 bordercolor="#111111" width="90%" bgcolor="#E8FFE8">
3109 <p>[<i>Note:</i> For ISO 9945/POSIX based operating systems the
3110 attributes are those copied by native API <code>stat(from.c_str(), &from_stat)</code>
3111 followed by <code>mkdir(to.c_str(),from_stat.st_mode)</code>. For
3112 Windows based operating systems the attributes are those copied by native
3113 API <code>CreateDirectoryExW(from.c_str(), to.c_str(), 0)</code>. <i>
3114 —end note</i>]</td>
3119 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3123 <pre>void copy_file(const path& from, const path& to);
3124 void copy_file(const path& from, const path& to, system::error_code& ec);</pre>
3126 <p><i>Effects: </i><code>copy_file(from, to, copy_option::fail_if_exists</code><i>[</i><code>, ec</code><i>]</i><code>)</code>.</p>
3128 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3131 <pre>void <a name="copy_file">copy_file</a>(const path& from, const path& to, <a href="#copy_option">copy_option</a> option);
3132 void <a name="copy_file2">copy_file</a>(const path& from, const path& to, <a href="#copy_option">copy_option</a> option, system::error_code& ec);</pre>
3134 <p><i>Effects:</i> If <code>option == copy_option::</code><code>fail_if_exists && exists(to)</code>, an error is reported. Otherwise, the contents and attributes of the file <code>from</code> resolves to are copied to the file <code>to</code> resolves to.</p>
3135 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3137 <pre>void <a name="copy_symlink">copy_symlink</a>(const path& existing_symlink, const path& new_symlink);
3138 void copy_symlink(const path& existing_symlink, const path& new_symlink, system::error_code& ec);</pre>
3140 <p><i>Effects: </i><code>create_symlink(read_symlink(existing_symlink</code><i>[</i><code>, ec</code><i>]</i><code>), new_symlink</code><i>[</i><code>, ec</code><i>]</i><code>)</code>.</p>
3142 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3145 <pre>bool <a name="create_directories">create_directories</a>(const path& p);
3146 bool <a name="create_directories2">create_directories</a>(const path& p, system::error_code& ec);</pre>
3148 <p><i>Effects:</i> Establishes the postcondition by calling <code>
3149 create_directory()</code> for any element of <code>p</code> that does not
3151 <p><i>Postcondition:</i> <code>is_directory(p)</code></p>
3152 <p><i>Returns:</i> <code>true</code> if a new directory was created, otherwise <code>
3154 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3155 <p><i>Complexity:</i> <i>O(n+1)</i> where <i>n</i> is the number of elements
3156 of <code>p</code> that do not exist.</p>
3158 <pre>bool <a name="create_directory">create_directory</a>(const path& p);
3159 bool <a name="create_directory2">create_directory</a>(const path& p, system::error_code& ec);</pre>
3161 <p><i>Effects:</i> Establishes the postcondition by attempting to create the
3162 directory <code>p</code> resolves to, as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/mkdir.html">
3163 mkdir()</a></code> with a second argument of S_IRWXU|S_IRWXG|S_IRWXO. Creation
3164 failure because <code>p</code> resolves to an existing directory shall not be
3165 treated as an error. </p>
3166 <p><i>Postcondition:</i> <code>is_directory(p)</code></p>
3167 <p><i>Returns:</i> <code>true</code> if a new directory was created, otherwise <code>false</code>.</p>
3168 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3170 <pre>void <a name="create_directory_symlink">create_directory_symlink</a>(const path& to, const path& new_symlink);
3171 void create_directory_symlink(const path& to, const path& new_symlink, system::error_code& ec);</pre>
3173 <p><i>Effects:</i> Establishes the postcondition, as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/symlink.html">symlink()</a></code>.</p>
3175 Postcondition:</i> <code>new_symlink</code> resolves to a symbolic link file that
3176 contains an unspecified representation of <code>to</code>.</p>
3177 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3178 <p>[<i>Note:</i> Some operating systems, such as Windows, require symlink creation to
3179 identify that the link is to a directory. Portable code should use <code>create_directory_symlink()</code> to create directory symlinks rather than <code>create_symlink()</code> <i>—end note</i>]</p>
3180 <p>[<i>Note:</i> Some operating systems do not support symbolic links at all or support
3181 them only for regular files.
3182 Some file systems do not
3184 symbolic links regardless of the operating system - the FAT file system used on
3185 memory cards and flash drives, for example. <i>—end note</i>]</p>
3187 <pre>void <a name="create_hard_link">create_hard_link</a>(const path& to, const path& new_hard_link);
3188 void <a name="create_hard_link2">create_hard_link</a>(const path& to, const path& new_hard_link, system::error_code& ec);</pre>
3190 <p><i>Effects:</i> Establishes the postcondition, as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/link.html">link()</a></code>.</p>
3191 <p><i>Postcondition:</i></p>
3193 <li> <code>exists(to) &&
3194 exists(</code><code>new_hard_link</code><code>) && equivalent(to,
3196 </code><code>new_hard_link</code><code>)</code></li>
3197 <li>The contents of the file or directory
3198 <code>to</code> resolves to are unchanged.</li>
3200 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3201 <p>[<i>Note:</i> Some operating systems do not support hard links at all or support
3202 them only for regular files. Some file systems do not support hard
3203 links regardless of the operating system - the FAT file system used on memory
3204 cards and flash drives, for example. Some file systems limit the number of
3205 links per file. <i>—end note</i>]</p>
3207 <pre>void <a name="create_symlink">create_symlink</a>(const path& to, const path& new_symlink);
3208 void <a name="create_symlink2">create_symlink</a>(const path& to, const path& new_symlink, system::error_code& ec);</pre>
3210 <p><i>Effects:</i> Establishes the postcondition, as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/symlink.html">symlink()</a></code>.</p>
3212 Postcondition:</i> <code>new_symlink</code> resolves to a symbolic link file that
3213 contains an unspecified representation of <code>to</code>.</p>
3214 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3215 <p>[<i>Note:</i> Some operating systems do not support symbolic links at all or support
3216 them only for regular files.
3217 Some file systems do not
3219 symbolic links regardless of the operating system - the FAT system used on
3220 memory cards and flash drives, for example. <i>—end note</i>]</p>
3222 <pre>path <a name="current_path">current_path</a>();
3223 path <a name="current_path2">current_path</a>(system::error_code& ec);</pre>
3225 <p><i>Returns:</i> The current working directory path, as if by ISO/IEC
3226 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/getcwd.html">getcwd()</a></code>. <code>is_absolute()</code> is true for the returned path.</p>
3227 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3228 <p>[<i>Note: </i>The <code>current_path()</code> name was chosen to emphasize that the return is a
3229 path, not just a single directory name.</p>
3230 <p>The current path as returned by many operating systems is a dangerous
3231 global variable. It may be changed unexpectedly by a third-party or system
3232 library functions, or by another thread. <i>—end note</i>]</p>
3234 <pre>void current_path(const path& p);
3235 void current_path(const path& p, system::error_code& ec);</pre>
3237 <p><i>Effects:</i> Establishes the postcondition, as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/chdir.html">chdir()</a></code>.</p>
3238 <p><i>Postcondition:</i> <code>equivalent(p, current_path())</code>.</p>
3239 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3240 <p>[<i>Note: </i>The current path for many operating systems is a dangerous
3241 global state. It may be changed unexpectedly by a third-party or system
3242 library functions, or by another thread. <i>—end note</i>]</p>
3244 <pre>bool <a name="exists">exists</a>(file_status s) noexcept;</pre>
3246 <p><i>Returns:</i> <code>status_known(s) && s.type() != file_not_found</code></p>
3248 <pre>bool <a name="exists2">exists</a>(const path& p);
3249 bool <a name="exists3">exists</a>(const path& p, system::error_code& ec) noexcept;</pre>
3251 <p><i>Returns:</i> <code>exists(status(p))</code> or <code>exists(status(p, ec))</code>,
3252 respectively. If ec != 0 and an error</p>
3253 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3255 <pre><code>bool <a name="equivalent">equivalent</a>(const path& p1, const path& p2);
3256 bool <a name="equivalent2">equivalent</a>(const path& p1, const path& p2, system::error_code& ec);</code></pre>
3258 <p><i>Effects:</i> Determines <code>file_status s1</code> and <code>s2</code>, as if by <code>status(p1)</code> and <code>status(p2)</code>,
3260 <p><i>Returns:</i> <code>true</code>, if <code>sf1 ==
3261 sf2</code> and <code>p1</code> and <code>p2</code> resolve to the same file
3262 system entity, else <code>false</code>.</p>
3264 <p>Two paths are considered to resolve to the same
3265 file system entity if two candidate entities reside on the same device at the
3266 same location. This is determined as if by the values of the ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">stat</a></code> structure<code>,</code> obtained as if by <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/stat.html">stat()</a></code> for the two paths, having equal <code>st_dev</code> values
3267 and equal <code>st_ino</code> values.</p>
3268 <p>[<i>Note:</i> ISO/IEC 9945 requires that <i>"st_dev</i> must be unique within a Local Area Network". Conservative
3269 ISO/IEC 9945 implementations may also wish to check for equal <code>st_size</code> and <code>st_mtime</code> values. <i>Windows</i> implementations may use <code>GetFileInformationByHandle()</code> as a surrogate for <code>stat()</code>,
3270 and consider "same" to be equal values for <code>dwVolumeSerialNumber</code>, <code>nFileIndexHigh</code>, <code>nFileIndexLow</code>, <code>nFileSizeHigh</code>, <code>nFileSizeLow</code>, <code>ftLastWriteTime.dwLowDateTime</code>, and <code>ftLastWriteTime.dwHighDateTime</code>. <i>—end note</i>]</p>
3272 <p><i>Throws:</i> <code>filesystem_error</code> if <code>(!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2))</code>,
3273 otherwise as specified in <a href="#Error-reporting">Error reporting</a>.</p>
3276 <pre>uintmax_t <a name="file_size">file_size</a>(const path& p);
3277 uintmax_t <a name="file_size2">file_size</a>(const path& p, system::error_code& ec);</pre>
3280 <p><i>Returns:</i> If <code>exists(p) && is_regular_file(p)</code>, the size
3282 of the file <code>p</code> resolves to, determined as if by the value of
3283 the ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">stat</a></code> structure member <code>st_size</code> obtained as if by
3284 ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/stat.html">stat()</a></code>.
3285 Otherwise, <code>static_cast<uintmax_t>(-1)</code>.</p>
3286 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3288 <pre>uintmax_t <a name="hard_link_count">hard_link_count</a>(const path& p);
3289 uintmax_t hard_link_count(const path& p, system::error_code& ec);</pre>
3292 <p><i>Returns:</i> The number of hard links for <code>p</code>.</p>
3293 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3297 <pre>const path& <a name="initial_path">initial_path</a>();
3298 const path& <a name="initial_path2">initial_path</a>(<code>system::error_code& ec</code>);</pre>
3300 <p><i>Returns:</i> <code>current_path()</code> as of the first call to <code>initial_path()</code>.</p>
3301 <p>[<i>Note:</i> <code>initial_path()</code> is not thread safe, and may return an undesirable result
3302 if called subsequent to a change to the current directory. These problems can
3303 be avoided by calling <code>initial_path()</code> immediately on entry to
3304 main(). <i>—end note</i>]</p>
3305 <p><i>Throws:</i> For the first call, as specified in <a href="#Error-reporting">Error reporting</a>. Subsequent calls throw nothing.</p>
3307 <pre>bool <code><a name="is_directory">is_directory</a></code>(file_status s) noexcept;</pre>
3309 <p><i>Returns:</i> <code>s.type() == directory_file</code></p>
3311 <pre><code>bool <a name="is_directory2">is_directory</a>(const path& p);
3312 bool <a name="is_directory3">is_directory</a>(const path& p, system::error_code& ec) noexcept;</code></pre>
3314 <p><i>Returns:</i> <code>is_directory(status(p))</code> or <code>is_directory(status(p, ec))</code>,
3316 <p><i>Throws:</i> <code>filesystem_error</code>; overload with <code>error_code&</code> throws
3319 <pre><code>bool <a name="is_empty">is_empty</a>(const path& p);
3320 bool <a name="is_empty2">is_empty</a></a>(const path& p, system::error_code& ec);</code></pre>
3322 <p><i>Effects:</i> Determines <code>file_status s</code>, as if by <code>status(p, ec)</code>.</p>
3323 <p><i>Returns:</i> <code>is_directory(s)<br>
3324 ? directory_iterator(p) == directory_iterator()<br>
3325 : file_size(p) == 0;</code></p>
3327 <pre>bool <code><a name="is_regular_file">is_regular_file</a></code>(file_status s) noexcept;</pre>
3329 <p><i>Returns:</i> <code>s.type() == regular_file</code></p>
3331 <pre><code>bool <a name="is_regular_file2">is_regular_file</a>(const path& p);</code></pre>
3333 <p><i>Returns:</i> <code>is_regular_file(status(p))</code>.</p>
3334 <p><i>Throws:</i> <code>filesystem_error</code> if <code>status(p)</code> would throw <code>filesystem_error.</code></p>
3336 <pre><code>bool <a name="is_regular_file3">is_regular_file</a>(const path& p, system::error_code& ec) noexcept;</code></pre>
3338 <p><i>Effects:</i> Sets <code>ec</code> as if by <code>status(p, ec)</code>. [<i>Note:</i> <code>status_error</code>, <code>file_not_found</code> and <code>type_unknown</code> cases set <code>ec</code> to error values. To distinguish between cases, call the <code>status</code> function directly. <i>—end
3340 <p><i>Returns:</i> <code>is_regular_file(status(p, ec))</code>.</p>
3342 <pre>bool <a name="is_other">is_other</a>(file_status s) noexcept;</pre>
3344 <p><i>Returns:</i> <code>return exists(s) && !is_regular_file(s) && !is_directory(s) && !is_symlink(s)</code></p>
3346 <pre><code>bool <a name="is_other2">is_other</a>(const path& p);
3347 bool <a name="is_other3">is_other</a>(const path& p, system::error_code& ec) noexcept;</code></pre>
3349 <p><i>Returns:</i> <code>is_other(status(p))</code> or <code>is_other(status(p, ec))</code>,
3351 <p><i>Throws:</i> <code>filesystem_error</code>; overload with <code>error_code&</code> throws
3354 <pre>bool <a name="is_symlink">is_symlink</a>(file_status s) noexcept;</pre>
3356 <p><i>Returns:</i> <code>s.type() == symlink_file</code></p>
3358 <pre><code>bool <a name="is_symlink2">is_symlink</a>(const path& p);
3359 bool <a name="is_symlink3">is_symlink</a>(const path& p, system::error_code& ec) noexcept;</code></pre>
3361 <p><i>Returns:</i> <code>is_symlink(symlink_status(p))</code> or <code>is_symlink(symlink_status(p, ec))</code>,
3363 <p><i>Throws:</i> <code>filesystem_error</code>; overload with <code>error_code&</code> throws
3366 <pre>std::time_t <a name="last_write_time">last_write_time</a>(const path& p);
3367 std::time_t <a name="last_write_time2">last_write_time</a>(const path& p<code>, system::error_code& ec</code>);</pre>
3369 <p><i>Returns:</i> The time of last data modification of <code>p</code>, determined as if by the
3370 value of the ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">stat</a></code> structure member <code>st_mtime</code> obtained
3371 as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/stat.html">stat()</a></code>.</p>
3372 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3374 <pre>void <a name="last_write_time3">last_write_time</a>(const path& p, const std::time_t new_time);
3375 void <a name="last_write_time4">last_write_time</a>(const path& p, const std::time_t new_time<code>, system::error_code& ec</code>);</pre>
3377 <p><i>Effects:</i> Sets the time of last data modification of the file
3378 resolved to by <code>p</code> to <code>new_time</code>, as if by ISO/IEC
3379 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/stat.html">stat()</a></code> followed by
3380 ISO/IEC 9945 <a href="http://www.opengroup.org/onlinepubs/000095399/functions/utime.html"><code>utime()</code></a>.</p>
3381 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3382 <p>[<i>Note:</i> A postcondition of <code>last_write_time(p) == new_time</code> is not specified since it might not hold for file systems
3383 with coarse time granularity. <i>—end note</i>]</p>
3385 <pre>void <a name="permissions">permissions</a>(const path& p, <a href="#symlink_perms">perms</a> prms);
3386 void permissions(const path& p, <a href="#symlink_perms">perms</a> prms, system::error_code& ec);</pre>
3389 <i>Requires:</i> <code>!((prms & add_perms) && (prms & remove_perms))</code>.</p>
3390 <p><i>Effects:</i> Applies the effective permissions bits from <code>prms</code> to the file <code>p</code> resolves to, as if by
3391 ISO/IEC 9945 <code><a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmodat.html">fchmodat()</a></code>. The effective permission bits are determined as
3392 specified by the following table. </p>
3393 <table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
3395 <td><b>bits present in <code>prms</code></b></td>
3396 <td><b>Effective bits applied</b></td>
3399 <td>Neither <code>add_perms</code> nor <code>remove_perms</code></td>
3400 <td><code>prms & perms_mask</code></td>
3403 <td><code>add_perms</code></td>
3405 <p><code>status(p).permissions() | (prms & <a href="#perms_mask">perms_mask</a>)</code> </td>
3408 <td><code>remove_perms</code></td>
3409 <td><code>status(p)</code><code>.permissions() & ~(prms & <a href="#perms_mask">perms_mask</a>) </code></td>
3412 <p>[<i>Note:</i> Conceptually permissions are viewed as bits, but the actual
3413 implementation may use some other mechanism. -- <i>end note</i>]</p>
3414 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3416 <pre>path <a name="read_symlink">read_symlink</a>(const path& p);
3417 path read_symlink(const path& p, system::error_code& ec);</pre>
3419 <p><i>Returns:</i> If <code>p</code> resolves to a symbolic
3420 link, a <code>path</code> object containing the contents of that symbolic
3421 link. Otherwise an empty <code>path</code> object.</p>
3422 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>. [<i>Note:</i> It is an error if <code>p</code> does not
3423 resolve to a symbolic link. <i>—end note</i>]</p>
3425 <pre>path <a name="op-relative">relative</a>(const path& p, system::error_code& ec);</pre>
3427 <p><i>Returns:</i> <code>relative(p, current_path(), ec)</code>.</p>
3428 <p><i>Throws:</i> As specified in Error reporting.</p>
3430 <pre>path relative(const path& p, const path& base=current_path());
3431 path relative(const path& p, const path& base, system::error_code& ec);</pre>
3433 <p><i>Overview:</i> Returns <code>p</code> made relative to <code>base</code>.
3434 Treats empty or identical paths as corner cases, not errors. Resolves symlinks
3435 and normalizes both <code>p</code> and <code>base</code> before other
3437 <p><i>Returns:</i> <code><a href="#weakly_canonical">weakly_canonical</a>(p).<a href="#lex-relative">lexically_relative</a>(<a href="#weakly_canonical">weakly_canonical</a>(base))</code>. The second form returns <code>path()</code>
3438 if an error occurs.</p>
3439 <p><i>Throws:</i> As specified in Error reporting.</p>
3441 <pre>bool <a name="remove">remove</a>(const path& p);
3442 bool <a name="remove2">remove</a>(const path& p, system::error_code& ec);</pre>
3444 <p><i>Effects:</i> If <code>exists(symlink_status(p,ec))</code>, it is
3446 as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/remove.html">remove()</a></code>.</p>
3448 <p>[<i>Note:</i> A symbolic link is itself removed, rather than the file it
3449 resolves to being removed. <i>—end note</i>]</p>
3451 <p><i>Postcondition:</i> <code>!exists(symlink_status(p))</code>.</p>
3452 <p><i>Returns:</i> <code>false</code> if p did not exist in the first
3453 place, otherwise <code>true</code>.</p>
3454 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3456 <pre>uintmax_t <a name="remove_all">remove_all</a>(const path& p);
3457 uintmax_t <a name="remove_all2">remove_all</a>(const path& p, system::error_code& ec);</pre>
3459 <p><i>Effects:</i> Recursively deletes the contents of p if it exists,
3460 then deletes file <code>p</code> itself,
3461 as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/remove.html">remove()</a></code>.</p>
3463 <p>[<i>Note:</i> A symbolic link is itself removed, rather than the file it
3464 resolves to being removed. <i>—end note</i>]</p>
3466 <p><i>Postcondition:</i> <code>!exists(p)</code></p>
3467 <p><i>Returns:</i> The number of files removed.</p>
3468 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3470 <pre>void <a name="rename">rename</a>(const path& old_p, const path& new_p);
3471 void <a name="rename2">rename</a>(const path& old_p, const path& new_p, system::error_code& ec);</pre>
3473 <p><i>Effects:</i> Renames <code>old_p</code> to <code>new_p</code>, as if by
3474 ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/rename.html">rename()</a></code>.</p>
3476 <p>[<i>Note:</i> If <code>old_p</code> and <code>new_p</code> resolve to the
3477 same existing file, no action is taken. Otherwise, if <code>new_p</code> resolves to an
3478 existing non-directory file, it is removed, while if <code>new_p</code> resolves to an
3479 existing directory, it is removed if empty on ISO/IEC 9945 but is an error on Windows. A symbolic link is itself renamed, rather than
3480 the file it resolves to being renamed. <i>—end note</i>]</p>
3482 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3484 <pre>void <a name="resize_file">resize_file</a>(const path& p, uintmax_t new_size);
3485 void <a name="resize_file2">resize_file</a>(const path& p, uintmax_t new_size, system::error_code& ec);</pre>
3487 <p><i>Postcondition:</i> <code>file_size() == new_size</code>.</p>
3488 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3489 <p><i>Remarks:</i> Achieves its postconditions as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/truncate.html">truncate()</a></code>.</p>
3491 <pre>space_info <a name="space">space</a>(const path& p);
3492 space_info <a name="space2">space</a>(const path& p, system::error_code& ec);</pre>
3494 <p><i>Returns:</i> An object of type <code><a href="#space_info">space_info</a></code>. The value of the <code>space_info</code> object is determined as if by
3495 using ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/statvfs.html"
3496 style="text-decoration: none">statvfs()</a></code> to obtain an ISO/IEC 9945 struct
3497 <code><a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/statvfs.h.html" style="text-decoration: none">statvfs</a></code>,
3498 and then multiplying its <code>f_blocks</code>, <code>f_bfree</code>,
3499 and <code>f_bavail</code> members by its <code>f_frsize</code> member,
3500 and assigning the results to the <code>capacity</code>, <code>free</code>,
3501 and <code>available</code> members respectively. Any members for which the
3502 value cannot be determined shall be set to -1.</p>
3503 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3505 <pre><a href="#file_status">file_status</a> <a name="status">status</a>(const path& p);</pre>
3507 <p><i>Effects: </i>As if:</p>
3509 <pre>system::error_code ec;
3510 file_status result = status(p, ec);
3511 if (result == status_error)
3512 throw filesystem_error(<i>implementation-supplied-message</i>, p, ec);
3513 return result;</pre>
3515 <p><i>Returns:</i> See above.</p>
3516 <p><i>Throws:</i> <code>filesystem_error</code>.
3517 [<i>Note:</i> <code>result</code> values of <code>file_status(file_not_found)</code>and <code>file_status(type_unknown)</code> are not considered failures and do not
3518 cause an exception to be
3519 thrown.<i> —end note</i>] </p>
3521 <pre><a href="#file_status">file_status</a> <a name="status2">status</a>(const path& p, system::error_code& ec) noexcept;</pre>
3523 <p><i>Effects: </i></p>
3525 <p>If possible, determines the attributes
3526 of the file <code>p</code> resolves to, as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/stat.html">stat()</a></code>.</p>
3527 If, during attribute determination, the underlying file system API reports
3528 an error, sets <code>ec</code> to indicate the specific error reported.
3529 Otherwise, <code>ec.clear()</code>.<blockquote>
3530 <p>[<i>Note:</i> This allows users to inspect the specifics of underlying
3531 API errors even when the value returned by <code>status()</code> is not <code>file_status(status_error)</code>. <i>—end note</i>]</p>
3534 <p><i>Returns:</i></p>
3536 <p>If <code>ec != error_code()</code>:</p>
3538 <li>If the specific error indicates that <code>p</code> cannot be resolved
3539 because some element of the path does not exist, return <code>
3540 file_status(file_not_found)</code>. [<i>Note:</i> ISO/IEC 9945 errors that
3541 indicate this are ENOENT or ENOTDIR. Windows equivalents
3542 include ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND, ERROR_INVALID_NAME,
3543 ERROR_INVALID_PARAMETER, ERROR_BAD_PATHNAME, and ERROR_BAD_NETPATH. <i>--
3546 <li>Otherwise, if the specific error indicates that <code>p</code> can be resolved
3547 but the attributes cannot be determined, return <code>
3548 file_status(type_unknown)</code>. [<i>Note: </i>For example, Windows
3549 ERROR_SHARING_VIOLATION errors. For ISO/IEC 9945, the case never arises. <i>—end
3552 <li>Otherwise, return <code>
3553 file_status(status_error)</code>.</li>
3556 <p>[<i>Note:</i> These semantics distinguish between <code>p</code> being known not to exist, <code>p</code> existing but not being able to determine its attributes,
3557 and there being an error that prevents even knowing if <code>p</code> exists. These
3558 distinctions are important to some use cases. <i>—end note</i>]</p>
3562 <li>If the attributes indicate a regular file, as if by ISO/IEC 9945 <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">S_ISREG()</a>,
3564 file_status(regular_file)</code>. [<i>Note:</i> <code>
3565 regular_file</code> implies appropriate <code><fstream></code> operations
3566 would succeed, assuming no hardware, permission, access, or file system
3569 <code>regular_file</code> does not necessarily imply <code><fstream></code> operations would
3570 fail on a directory.
3571 <i>—end note</i>]<br>
3573 <li>Otherwise, if the attributes indicate a directory, as if by ISO/IEC 9945
3574 <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">S_ISDIR()</a>,
3576 file_status(directory_file)</code>. [<i>Note:</i> <code>directory_file</code> implies <code>
3577 directory_iterator(p)</code>would succeed.
3578 <i>—end note</i>]<br>
3580 <li>Otherwise, if the attributes indicate a block special file, as if by ISO/IEC 9945
3581 <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">S_ISBLK()</a>,
3583 file_status(block_file)</code>.<br>
3585 <li>Otherwise, if the attributes indicate a character special file, as if by ISO/IEC 9945
3586 <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">S_ISCHR()</a>,
3588 file_status(character_file)</code>.<br>
3590 <li>Otherwise, if the attributes indicate a fifo or pipe file, as if by
3592 <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">S_ISFIFO()</a>,
3594 file_status(fifo_file)</code>.<br>
3596 <li>Otherwise, if the attributes indicate a socket, as if by ISO/IEC
3598 <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">S_ISSOCK()</a>,
3600 file_status(socket_file)</code>.<br>
3602 <li>Otherwise, return <code>
3603 file_status(type_unknown)</code>.</li>
3606 <p><i>Remarks:</i> If a symbolic link is encountered during pathname
3608 pathname resolution continues using the contents of the symbolic link.</p>
3610 <pre>bool <a name="status_known">status_known</a>(file_status s) noexcept;</pre>
3612 <p><i>Returns:</i> <code>s.type() != status_error</code></p>
3614 <pre>file_status <a name="symlink_status">symlink_status</a>(const path& p);
3615 file_status <a name="symlink_status2">symlink_status</a>(const path& p, system::error_code& ec) noexcept;</pre>
3617 <p><i>Effects:</i> Same as <a href="#status">status()</a>, above,
3618 except that the attributes
3619 of <code>p</code> are determined as if by ISO/IEC 9945 <code><a href="http://www.opengroup.org/onlinepubs/000095399/functions/lstat.html">lstat()</a></code>.</p>
3622 <p><i>Returns:</i> Same as <a href="#status">status()</a>, above, except
3623 that if the attributes indicate a symbolic link, as if by ISO/IEC 9945 <a class="external" href="http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/stat.h.html">S_ISLNK()</a>, return <code>file_status(symlink_file)</code>.</p>
3624 <p><i>Remarks:</i> Pathname resolution terminates if <code>p</code> names a symbolic link.</p>
3625 <p><i>Throws:</i> <code>filesystem_error</code>; overload with <code>error_code&</code> throws
3628 <pre>path <a name="system_complete">system_complete</a>(const path& p);
3629 path <a name="system_complete2">system_complete</a>(const path& p, system::error_code& ec);</pre>
3631 <p><i>Effects:</i> Composes an absolute path from <code>p</code>, using the
3632 same rules used by the operating system to resolve a path passed as the
3633 filename argument to standard library open functions.</p>
3634 <p><i>Returns:</i> The composed path.</p>
3635 <p><i>Postcondition:</i> For the returned path, <code>rp,</code> <code>rp.is_absolute()</code> is true.</p>
3636 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3637 <p>[<i>Note:</i> For ISO/IEC 9945, <code>system_complete(p)</code> has the same semantics as <code>complete(p, current_path())</code>.</p>
3638 <p><a name="windows_effects">For <i>Windows</i></a>, <code>system_complete(p)</code> has the
3639 same semantics as <code>complete(ph, current_path())</code> if <code>p.is_absolute() || !p.has_root_name()</code> or <code>p</code> and <code>base</code> have the same <code>root_name()</code>.
3640 Otherwise it acts like <code>complete(p, kinky)</code>, where <code>kinky</code> is the current directory for the <code>p.root_name()</code> drive. This will
3641 be the current directory of that drive the last time it was set, and thus may
3642 be <b>residue left over from a prior program</b> run by the command
3643 processor! Although these semantics are often useful, they are also very
3645 <p>See <a href="#complete_note"><i>complete()</i> note</a> for usage suggestions. <i>—end note</i>]</p>
3647 <pre>path <a name="temp_directory_path">temp_directory_path</a>();
3648 path temp_directory_path(system::error_code& ec);</pre>
3650 <p><i>Returns:</i> A directory path suitable for temporary files under the
3651 conventions of the operating system. The specifics of how this path is
3652 determined are implementation defined. An error shall be reported if<code> !exists(p)
3653 || !is_directory(p)</code>, where <code>p</code> is the path to be returned.</p>
3654 <p>ISO/IEC 9945: The path supplied by the first environment variable found in the
3655 list TMPDIR, TMP, TEMP, TEMPDIR. If none of these are found, <code>"/tmp"</code>,
3656 or, if macro <code>__ANDROID__ </code>is defined, <code>"/data/local/tmp"</code>.</p>
3657 <p><i>Windows:</i> The path reported by the <i>Windows</i> <code>GetTempPath</code> API function.</p>
3658 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3659 <p>[<i>Note: </i>The <code>temp_directory_path()</code> name was chosen to emphasize that the return is a
3660 path, not just a single directory name. <i>—end note</i>]</p>
3662 <pre>path <a name="unique_path">unique_path</a>(const path& model="%%%%-%%%%-%%%%-%%%%");
3663 path unique_path(const path& model, system::error_code& ec);</pre>
3665 <p>The <code>unique_path</code> function generates a path name suitable for
3666 creating temporary files, including directories. The name is based
3667 on a model that uses the percent sign character to specify replacement by a
3668 random hexadecimal digit. [<i>Note:</i> The more bits of randomness in the
3669 generated path name, the less likelihood of prior existence or being guessed.
3670 Each replacement hexadecimal digit in the model adds four bits of randomness.
3671 The default model thus provides 64 bits of randomness. This is sufficient for
3672 most applications. <i>—end note</i>]</p>
3673 <p><i>Returns:</i> A path identical to <code>model</code>, except that each
3674 occurrence of a percent sign character is replaced by a random hexadecimal
3675 digit character in the range 0-9, a-f.</p>
3676 <p><i>Throws:</i> As specified in <a href="#Error-reporting">Error reporting</a>.</p>
3677 <p><i>Remarks:</i> Implementations are encouraged to obtain the required
3678 randomness via a <a href="http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator">cryptographically secure pseudo-random number generator</a>, such as one
3679 provided by the operating system. [<i>Note</i>: Such generators may block
3680 until sufficient entropy develops. <i>—end note</i>]</p>
3682 <pre>path <a name="weakly_canonical">weakly_canonical</a>(const path& p);
3683 path weakly_canonical(const path& p, system::error_code& ec);</pre>
3685 <p><i>Overview:</i> Returns <code>p</code> with symlinks resolved and the
3686 result normalized.</p>
3687 <p><i>Returns: </i>A path composed of the result of calling the <code>
3688 canonical</code> function on a path composed of the leading elements of <code>
3689 p</code> that exist, if any, followed by the elements of <code>p</code> that
3690 do not exist, if any.</p>
3691 <p><i>Postcondition:</i> The returned path is in
3692 <a href="#normal-form">
3693 normal form</a>.</p>
3694 <p><i>Remarks:</i> Uses <code>operator/=</code> to compose the returned path.
3695 Uses the <code>status</code> function to determine existence.</p>
3696 <p><i>Remarks:</i> Implementations are encouraged to avoid unnecessary
3697 normalization such as when <code>canonical</code> has already been called on
3698 the entirety of <code>p</code>.</p>
3699 <p><i>Throws:</i> As specified in Error reporting.</p>
3703 <!-- generate-section-numbers=false -->
3706 <h3><a name="File-streams">File streams</a> -
3707 <a href="../../../boost/filesystem/fstream.hpp"><boost/filesystem/fstream.hpp></a></h3>
3708 <p>Replacements are provided for the file stream classes from the C++ standard
3709 library's <code><fstream></code> header. These replacement classes
3710 publicly inherit from the standard library classes. In the Boost.Filesystem
3711 version, constructors and open functions take <code>const path&</code> arguments
3713 const char*</code> arguments. There are no other differences in syntax or
3715 <pre>namespace boost
3717 namespace filesystem
3719 template < class charT, class traits = std::char_traits<charT> >
3720 class basic_filebuf : public std::basic_filebuf<charT,traits>
3723 basic_filebuf<charT,traits>*
3724 open(const path& p, std::ios_base::openmode mode);
3727 template < class charT, class traits = std::char_traits<charT> >
3728 class basic_ifstream : public std::basic_ifstream<charT,traits>
3731 explicit basic_ifstream(const path& p, std::ios_base::openmode mode=std::ios_base::in)
3732 void open(const path& p, std::ios_base::openmode mode=std::ios_base::in);
3735 template < class charT, class traits = std::char_traits<charT> >
3736 class basic_ofstream : public std::basic_ofstream<charT,traits>
3739 explicit basic_ofstream(const path& p, std::ios_base::openmode mode=std::ios_base::out);
3740 void open(const path& p, std::ios_base::openmode mode=std::ios_base::out);
3743 template < class charT, class traits = std::char_traits<charT> >
3744 class basic_fstream : public std::basic_fstream<charT,traits>
3747 explicit basic_fstream(const path& p,
3748 std::ios_base::openmode mode=std::ios_base::in | std::ios_base::out);
3749 void open(const path& p,
3750 std::ios_base::openmode mode=std::ios_base::in | std::ios_base::out);
3753 typedef basic_filebuf<char> filebuf;
3754 typedef basic_ifstream<char> ifstream;
3755 typedef basic_ofstream<char> ofstream;
3756 typedef basic_fstream<char> fstream;
3758 typedef basic_filebuf<wchar_t> wfilebuf;
3759 typedef basic_ifstream<wchar_t> wifstream;
3760 typedef basic_fstream<wchar_t> wfstream;
3761 typedef basic_ofstream<wchar_t> wofstream;
3763 } // namespace filesystem
3764 } // namespace boost</pre>
3768 <h2><a name="path-decomposition-table">Path decomposition table</a></h2>
3769 <p>The table is generated by a program compiled with the Boost implementation.</p>
3770 <p>Shaded entries indicate cases where ISO/IEC 9945 (POSIX) and Windows implementations yield different results. The top value is the
3771 ISO/IEC 9945 result and the bottom value is the Windows result. <br>
3772 <table border="1" cellspacing="0" cellpadding="5">
3774 <tr><td><b>Constructor<br>argument</b></td>
3775 <td><b>Iteration<br>over<br>Elements</b></td>
3776 <td><b><code>string()</code></b></td>
3777 <td><b><code>generic_<br>string()</code></b></td>
3778 <td><b><code>root_<br>path()</code></b></td>
3779 <td><b><code>root_<br>name()</code></b></td>
3780 <td><b><code>root_<br>directory()</code></b></td>
3781 <td><b><code>relative_<br>path()</code></b></td>
3782 <td><b><code>parent_<br>path()</code></b></td>
3783 <td><b><code>filename()</code></b></td>
3786 <td><font size="-1"><i>empty</i></font></td>
3787 <td><font size="-1"><i>empty</i></font></td>
3788 <td><font size="-1"><i>empty</i></font></td>
3789 <td><font size="-1"><i>empty</i></font></td>
3790 <td><font size="-1"><i>empty</i></font></td>
3791 <td><font size="-1"><i>empty</i></font></td>
3792 <td><font size="-1"><i>empty</i></font></td>
3793 <td><font size="-1"><i>empty</i></font></td>
3794 <td><font size="-1"><i>empty</i></font></td>
3795 <td><font size="-1"><i>empty</i></font></td>
3798 <td><code>.</code></td>
3799 <td><code>.</code></td>
3800 <td><code>.</code></td>
3801 <td><code>.</code></td>
3802 <td><font size="-1"><i>empty</i></font></td>
3803 <td><font size="-1"><i>empty</i></font></td>
3804 <td><font size="-1"><i>empty</i></font></td>
3805 <td><code>.</code></td>
3806 <td><font size="-1"><i>empty</i></font></td>
3807 <td><code>.</code></td>
3810 <td><code>..</code></td>
3811 <td><code>..</code></td>
3812 <td><code>..</code></td>
3813 <td><code>..</code></td>
3814 <td><font size="-1"><i>empty</i></font></td>
3815 <td><font size="-1"><i>empty</i></font></td>
3816 <td><font size="-1"><i>empty</i></font></td>
3817 <td><code>..</code></td>
3818 <td><font size="-1"><i>empty</i></font></td>
3819 <td><code>..</code></td>
3822 <td><code>foo</code></td>
3823 <td><code>foo</code></td>
3824 <td><code>foo</code></td>
3825 <td><code>foo</code></td>
3826 <td><font size="-1"><i>empty</i></font></td>
3827 <td><font size="-1"><i>empty</i></font></td>
3828 <td><font size="-1"><i>empty</i></font></td>
3829 <td><code>foo</code></td>
3830 <td><font size="-1"><i>empty</i></font></td>
3831 <td><code>foo</code></td>
3834 <td><code>/</code></td>
3835 <td><code>/</code></td>
3836 <td><code>/</code></td>
3837 <td><code>/</code></td>
3838 <td><code>/</code></td>
3839 <td><font size="-1"><i>empty</i></font></td>
3840 <td><code>/</code></td>
3841 <td><font size="-1"><i>empty</i></font></td>
3842 <td><font size="-1"><i>empty</i></font></td>
3843 <td><code>/</code></td>
3846 <td><code>/foo</code></td>
3847 <td><code>/,foo</code></td>
3848 <td><code>/foo</code></td>
3849 <td><code>/foo</code></td>
3850 <td><code>/</code></td>
3851 <td><font size="-1"><i>empty</i></font></td>
3852 <td><code>/</code></td>
3853 <td><code>foo</code></td>
3854 <td><code>/</code></td>
3855 <td><code>foo</code></td>
3858 <td><code>foo/</code></td>
3859 <td><code>foo,.</code></td>
3860 <td><code>foo/</code></td>
3861 <td><code>foo/</code></td>
3862 <td><font size="-1"><i>empty</i></font></td>
3863 <td><font size="-1"><i>empty</i></font></td>
3864 <td><font size="-1"><i>empty</i></font></td>
3865 <td><code>foo/</code></td>
3866 <td><code>foo</code></td>
3867 <td><code>.</code></td>
3870 <td><code>/foo/</code></td>
3871 <td><code>/,foo,.</code></td>
3872 <td><code>/foo/</code></td>
3873 <td><code>/foo/</code></td>
3874 <td><code>/</code></td>
3875 <td><font size="-1"><i>empty</i></font></td>
3876 <td><code>/</code></td>
3877 <td><code>foo/</code></td>
3878 <td><code>/foo</code></td>
3879 <td><code>.</code></td>
3882 <td><code>foo/bar</code></td>
3883 <td><code>foo,bar</code></td>
3884 <td><code>foo/bar</code></td>
3885 <td><code>foo/bar</code></td>
3886 <td><font size="-1"><i>empty</i></font></td>
3887 <td><font size="-1"><i>empty</i></font></td>
3888 <td><font size="-1"><i>empty</i></font></td>
3889 <td><code>foo/bar</code></td>
3890 <td><code>foo</code></td>
3891 <td><code>bar</code></td>
3894 <td><code>/foo/bar</code></td>
3895 <td><code>/,foo,bar</code></td>
3896 <td><code>/foo/bar</code></td>
3897 <td><code>/foo/bar</code></td>
3898 <td><code>/</code></td>
3899 <td><font size="-1"><i>empty</i></font></td>
3900 <td><code>/</code></td>
3901 <td><code>foo/bar</code></td>
3902 <td><code>/foo</code></td>
3903 <td><code>bar</code></td>
3906 <td><code>//net</code></td>
3907 <td><code>//net</code></td>
3908 <td><code>//net</code></td>
3909 <td><code>//net</code></td>
3910 <td><code>//net</code></td>
3911 <td><code>//net</code></td>
3912 <td><font size="-1"><i>empty</i></font></td>
3913 <td><font size="-1"><i>empty</i></font></td>
3914 <td><font size="-1"><i>empty</i></font></td>
3915 <td><code>//net</code></td>
3918 <td><code>//net/foo</code></td>
3919 <td><code>//net,/,foo</code></td>
3920 <td><code>//net/foo</code></td>
3921 <td><code>//net/foo</code></td>
3922 <td><code>//net/</code></td>
3923 <td><code>//net</code></td>
3924 <td><code>/</code></td>
3925 <td><code>foo</code></td>
3926 <td><code>//net/</code></td>
3927 <td><code>foo</code></td>
3930 <td><code>///foo///</code></td>
3931 <td><code>/,foo,.</code></td>
3932 <td><code>///foo///</code></td>
3933 <td><code>///foo///</code></td>
3934 <td><code>/</code></td>
3935 <td><font size="-1"><i>empty</i></font></td>
3936 <td><code>/</code></td>
3937 <td><code>foo///</code></td>
3938 <td><code>///foo</code></td>
3939 <td><code>.</code></td>
3942 <td><code>///foo///bar</code></td>
3943 <td><code>/,foo,bar</code></td>
3944 <td><code>///foo///bar</code></td>
3945 <td><code>///foo///bar</code></td>
3946 <td><code>/</code></td>
3947 <td><font size="-1"><i>empty</i></font></td>
3948 <td><code>/</code></td>
3949 <td><code>foo///bar</code></td>
3950 <td><code>///foo</code></td>
3951 <td><code>bar</code></td>
3954 <td><code>/.</code></td>
3955 <td><code>/,.</code></td>
3956 <td><code>/.</code></td>
3957 <td><code>/.</code></td>
3958 <td><code>/</code></td>
3959 <td><font size="-1"><i>empty</i></font></td>
3960 <td><code>/</code></td>
3961 <td><code>.</code></td>
3962 <td><code>/</code></td>
3963 <td><code>.</code></td>
3966 <td><code>./</code></td>
3967 <td><code>.,.</code></td>
3968 <td><code>./</code></td>
3969 <td><code>./</code></td>
3970 <td><font size="-1"><i>empty</i></font></td>
3971 <td><font size="-1"><i>empty</i></font></td>
3972 <td><font size="-1"><i>empty</i></font></td>
3973 <td><code>./</code></td>
3974 <td><code>.</code></td>
3975 <td><code>.</code></td>
3978 <td><code>/..</code></td>
3979 <td><code>/,..</code></td>
3980 <td><code>/..</code></td>
3981 <td><code>/..</code></td>
3982 <td><code>/</code></td>
3983 <td><font size="-1"><i>empty</i></font></td>
3984 <td><code>/</code></td>
3985 <td><code>..</code></td>
3986 <td><code>/</code></td>
3987 <td><code>..</code></td>
3990 <td><code>../</code></td>
3991 <td><code>..,.</code></td>
3992 <td><code>../</code></td>
3993 <td><code>../</code></td>
3994 <td><font size="-1"><i>empty</i></font></td>
3995 <td><font size="-1"><i>empty</i></font></td>
3996 <td><font size="-1"><i>empty</i></font></td>
3997 <td><code>../</code></td>
3998 <td><code>..</code></td>
3999 <td><code>.</code></td>
4002 <td><code>foo/.</code></td>
4003 <td><code>foo,.</code></td>
4004 <td><code>foo/.</code></td>
4005 <td><code>foo/.</code></td>
4006 <td><font size="-1"><i>empty</i></font></td>
4007 <td><font size="-1"><i>empty</i></font></td>
4008 <td><font size="-1"><i>empty</i></font></td>
4009 <td><code>foo/.</code></td>
4010 <td><code>foo</code></td>
4011 <td><code>.</code></td>
4014 <td><code>foo/..</code></td>
4015 <td><code>foo,..</code></td>
4016 <td><code>foo/..</code></td>
4017 <td><code>foo/..</code></td>
4018 <td><font size="-1"><i>empty</i></font></td>
4019 <td><font size="-1"><i>empty</i></font></td>
4020 <td><font size="-1"><i>empty</i></font></td>
4021 <td><code>foo/..</code></td>
4022 <td><code>foo</code></td>
4023 <td><code>..</code></td>
4026 <td><code>foo/./</code></td>
4027 <td><code>foo,.,.</code></td>
4028 <td><code>foo/./</code></td>
4029 <td><code>foo/./</code></td>
4030 <td><font size="-1"><i>empty</i></font></td>
4031 <td><font size="-1"><i>empty</i></font></td>
4032 <td><font size="-1"><i>empty</i></font></td>
4033 <td><code>foo/./</code></td>
4034 <td><code>foo/.</code></td>
4035 <td><code>.</code></td>
4038 <td><code>foo/./bar</code></td>
4039 <td><code>foo,.,bar</code></td>
4040 <td><code>foo/./bar</code></td>
4041 <td><code>foo/./bar</code></td>
4042 <td><font size="-1"><i>empty</i></font></td>
4043 <td><font size="-1"><i>empty</i></font></td>
4044 <td><font size="-1"><i>empty</i></font></td>
4045 <td><code>foo/./bar</code></td>
4046 <td><code>foo/.</code></td>
4047 <td><code>bar</code></td>
4050 <td><code>foo/..</code></td>
4051 <td><code>foo,..</code></td>
4052 <td><code>foo/..</code></td>
4053 <td><code>foo/..</code></td>
4054 <td><font size="-1"><i>empty</i></font></td>
4055 <td><font size="-1"><i>empty</i></font></td>
4056 <td><font size="-1"><i>empty</i></font></td>
4057 <td><code>foo/..</code></td>
4058 <td><code>foo</code></td>
4059 <td><code>..</code></td>
4062 <td><code>foo/../</code></td>
4063 <td><code>foo,..,.</code></td>
4064 <td><code>foo/../</code></td>
4065 <td><code>foo/../</code></td>
4066 <td><font size="-1"><i>empty</i></font></td>
4067 <td><font size="-1"><i>empty</i></font></td>
4068 <td><font size="-1"><i>empty</i></font></td>
4069 <td><code>foo/../</code></td>
4070 <td><code>foo/..</code></td>
4071 <td><code>.</code></td>
4074 <td><code>foo/../bar</code></td>
4075 <td><code>foo,..,bar</code></td>
4076 <td><code>foo/../bar</code></td>
4077 <td><code>foo/../bar</code></td>
4078 <td><font size="-1"><i>empty</i></font></td>
4079 <td><font size="-1"><i>empty</i></font></td>
4080 <td><font size="-1"><i>empty</i></font></td>
4081 <td><code>foo/../bar</code></td>
4082 <td><code>foo/..</code></td>
4083 <td><code>bar</code></td>
4086 <td><code>c:</code></td>
4087 <td><code>c:</code></td>
4088 <td><code>c:</code></td>
4089 <td><code>c:</code></td>
4090 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4091 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4092 <td><font size="-1"><i>empty</i></font></td>
4093 <td><code>c:</code><br><font size="-1"><i>empty</i></font></td>
4094 <td><font size="-1"><i>empty</i></font></td>
4095 <td><code>c:</code></td>
4098 <td><code>c:/</code></td>
4099 <td><code>c:,.</code><br><code>c:,/</code></td>
4100 <td><code>c:/</code></td>
4101 <td><code>c:/</code></td>
4102 <td><font size="-1"><i>empty</i></font><br><code>c:/</code></td>
4103 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4104 <td><font size="-1"><i>empty</i></font><br><code>/</code></td>
4105 <td><code>c:/</code><br><font size="-1"><i>empty</i></font></td>
4106 <td><code>c:</code></td>
4107 <td><code>.</code><br><code>/</code></td>
4110 <td><code>c:foo</code></td>
4111 <td><code>c:foo</code><br><code>c:,foo</code></td>
4112 <td><code>c:foo</code></td>
4113 <td><code>c:foo</code></td>
4114 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4115 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4116 <td><font size="-1"><i>empty</i></font></td>
4117 <td><code>c:foo</code><br><code>foo</code></td>
4118 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4119 <td><code>c:foo</code><br><code>foo</code></td>
4122 <td><code>c:/foo</code></td>
4123 <td><code>c:,foo</code><br><code>c:,/,foo</code></td>
4124 <td><code>c:/foo</code></td>
4125 <td><code>c:/foo</code></td>
4126 <td><font size="-1"><i>empty</i></font><br><code>c:/</code></td>
4127 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4128 <td><font size="-1"><i>empty</i></font><br><code>/</code></td>
4129 <td><code>c:/foo</code><br><code>foo</code></td>
4130 <td><code>c:</code><br><code>c:/</code></td>
4131 <td><code>foo</code></td>
4134 <td><code>c:foo/</code></td>
4135 <td><code>c:foo,.</code><br><code>c:,foo,.</code></td>
4136 <td><code>c:foo/</code></td>
4137 <td><code>c:foo/</code></td>
4138 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4139 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4140 <td><font size="-1"><i>empty</i></font></td>
4141 <td><code>c:foo/</code><br><code>foo/</code></td>
4142 <td><code>c:foo</code></td>
4143 <td><code>.</code></td>
4146 <td><code>c:/foo/</code></td>
4147 <td><code>c:,foo,.</code><br><code>c:,/,foo,.</code></td>
4148 <td><code>c:/foo/</code></td>
4149 <td><code>c:/foo/</code></td>
4150 <td><font size="-1"><i>empty</i></font><br><code>c:/</code></td>
4151 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4152 <td><font size="-1"><i>empty</i></font><br><code>/</code></td>
4153 <td><code>c:/foo/</code><br><code>foo/</code></td>
4154 <td><code>c:/foo</code></td>
4155 <td><code>.</code></td>
4158 <td><code>c:/foo/bar</code></td>
4159 <td><code>c:,foo,bar</code><br><code>c:,/,foo,bar</code></td>
4160 <td><code>c:/foo/bar</code></td>
4161 <td><code>c:/foo/bar</code></td>
4162 <td><font size="-1"><i>empty</i></font><br><code>c:/</code></td>
4163 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4164 <td><font size="-1"><i>empty</i></font><br><code>/</code></td>
4165 <td><code>c:/foo/bar</code><br><code>foo/bar</code></td>
4166 <td><code>c:/foo</code></td>
4167 <td><code>bar</code></td>
4170 <td><code>prn:</code></td>
4171 <td><code>prn:</code></td>
4172 <td><code>prn:</code></td>
4173 <td><code>prn:</code></td>
4174 <td><font size="-1"><i>empty</i></font><br><code>prn:</code></td>
4175 <td><font size="-1"><i>empty</i></font><br><code>prn:</code></td>
4176 <td><font size="-1"><i>empty</i></font></td>
4177 <td><code>prn:</code><br><font size="-1"><i>empty</i></font></td>
4178 <td><font size="-1"><i>empty</i></font></td>
4179 <td><code>prn:</code></td>
4182 <td><code>c:\</code></td>
4183 <td><code>c:\</code><br><code>c:,/</code></td>
4184 <td><code>c:\</code></td>
4185 <td><code>c:\</code><br><code>c:/</code></td>
4186 <td><font size="-1"><i>empty</i></font><br><code>c:\</code></td>
4187 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4188 <td><font size="-1"><i>empty</i></font><br><code>\</code></td>
4189 <td><code>c:\</code><br><font size="-1"><i>empty</i></font></td>
4190 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4191 <td><code>c:\</code><br><code>\</code></td>
4194 <td><code>c:foo</code></td>
4195 <td><code>c:foo</code><br><code>c:,foo</code></td>
4196 <td><code>c:foo</code></td>
4197 <td><code>c:foo</code></td>
4198 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4199 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4200 <td><font size="-1"><i>empty</i></font></td>
4201 <td><code>c:foo</code><br><code>foo</code></td>
4202 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4203 <td><code>c:foo</code><br><code>foo</code></td>
4206 <td><code>c:\foo</code></td>
4207 <td><code>c:\foo</code><br><code>c:,/,foo</code></td>
4208 <td><code>c:\foo</code></td>
4209 <td><code>c:\foo</code><br><code>c:/foo</code></td>
4210 <td><font size="-1"><i>empty</i></font><br><code>c:\</code></td>
4211 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4212 <td><font size="-1"><i>empty</i></font><br><code>\</code></td>
4213 <td><code>c:\foo</code><br><code>foo</code></td>
4214 <td><font size="-1"><i>empty</i></font><br><code>c:\</code></td>
4215 <td><code>c:\foo</code><br><code>foo</code></td>
4218 <td><code>c:foo\</code></td>
4219 <td><code>c:foo\</code><br><code>c:,foo,.</code></td>
4220 <td><code>c:foo\</code></td>
4221 <td><code>c:foo\</code><br><code>c:foo/</code></td>
4222 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4223 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4224 <td><font size="-1"><i>empty</i></font></td>
4225 <td><code>c:foo\</code><br><code>foo\</code></td>
4226 <td><font size="-1"><i>empty</i></font><br><code>c:foo</code></td>
4227 <td><code>c:foo\</code><br><code>.</code></td>
4230 <td><code>c:\foo\</code></td>
4231 <td><code>c:\foo\</code><br><code>c:,/,foo,.</code></td>
4232 <td><code>c:\foo\</code></td>
4233 <td><code>c:\foo\</code><br><code>c:/foo/</code></td>
4234 <td><font size="-1"><i>empty</i></font><br><code>c:\</code></td>
4235 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4236 <td><font size="-1"><i>empty</i></font><br><code>\</code></td>
4237 <td><code>c:\foo\</code><br><code>foo\</code></td>
4238 <td><font size="-1"><i>empty</i></font><br><code>c:\foo</code></td>
4239 <td><code>c:\foo\</code><br><code>.</code></td>
4242 <td><code>c:\foo/</code></td>
4243 <td><code>c:\foo,.</code><br><code>c:,/,foo,.</code></td>
4244 <td><code>c:\foo/</code></td>
4245 <td><code>c:\foo/</code><br><code>c:/foo/</code></td>
4246 <td><font size="-1"><i>empty</i></font><br><code>c:\</code></td>
4247 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4248 <td><font size="-1"><i>empty</i></font><br><code>\</code></td>
4249 <td><code>c:\foo/</code><br><code>foo/</code></td>
4250 <td><code>c:\foo</code></td>
4251 <td><code>.</code></td>
4254 <td><code>c:/foo\bar</code></td>
4255 <td><code>c:,foo\bar</code><br><code>c:,/,foo,bar</code></td>
4256 <td><code>c:/foo\bar</code></td>
4257 <td><code>c:/foo\bar</code><br><code>c:/foo/bar</code></td>
4258 <td><font size="-1"><i>empty</i></font><br><code>c:/</code></td>
4259 <td><font size="-1"><i>empty</i></font><br><code>c:</code></td>
4260 <td><font size="-1"><i>empty</i></font><br><code>/</code></td>
4261 <td><code>c:/foo\bar</code><br><code>foo\bar</code></td>
4262 <td><code>c:</code><br><code>c:/foo</code></td>
4263 <td><code>foo\bar</code><br><code>bar</code></td>
4266 <h2><a name="long-path-warning"></a>Warning: Long paths on Windows and the
4267 extended-length <b>\\?\ </b>prefix</h2>
4268 <p>The Microsoft Windows "Maximum Path Length Limitation" specifies:</p>
4270 <p>In the Windows API (with some exceptions ...), the maximum length for a path
4271 is MAX_PATH, which is defined as 260 characters.</p>
4272 <p>The Windows API has many functions that also have Unicode versions to permit
4273 an extended-length path for a maximum total path length of 32,767 characters.
4274 ... To specify an extended-length path, use the <b>"\\?\" prefix</b>. For
4275 example, "\\?\D:\<em>very long path</em>". <i>[C++ string literals require backslashes be doubled, of course.]</i></p>
4277 <p>Because most Boost.Filesystem operational functions just pass the contents of
4278 a class path object to the Windows API, they do work with the extended-length
4279 prefixes. But some won't work, because to the limitations imposed by Windows.
4280 Read the following cautions carefully!</p>
4281 <h3>Cautions for paths with extended-length prefixes</h3>
4283 <li>Individual components of a path are still are limited to whatever is
4284 supported for the particular filesystem, commonly 255 characters.</li>
4285 <li>Only backslashes are acceptable as directory separators. Slashes are
4286 not treated as separators.</li>
4287 <li>All paths must be absolute - relative paths are not allowed.</li>
4288 <li>Once an absolute path grows beyond 260 characters, it is essentially
4289 poisoned and all operations must use extended-length prefixes. So even a
4290 simple operation like <code>create_directory("a")</code> will fail if the
4291 absolute path of the resulting directory would exceed 260 characters.</li>
4292 <li>Certain Boost.Filesystem functions that decompose their argument path and
4293 then work on individual relative directories or files will not work properly
4294 with extended-length prefix paths.</li>
4296 <h2><a name="Acknowledgements">Acknowledgements</a></h2>
4297 <p>This Filesystem Library is dedicated to my wife, Sonda, who provided the
4298 support necessary to see both a trial implementation and the proposal itself
4299 through to completion. She gave me the strength to continue after a difficult
4300 year of cancer treatment in the middle of it all.</p>
4301 <p>Many people contributed technical comments, ideas, and suggestions to the
4302 Boost Filesystem Library. See <a href="http://www.boost.org/libs/filesystem/doc/index.htm#Acknowledgements">http://www.boost.org/libs/filesystem/doc/index.htm#Acknowledgements</a>.</p>
4303 <p>Dietmar Kuehl contributed the original Boost Filesystem Library directory_iterator design. Peter Dimov, Walter Landry, Rob Stewart, and Thomas
4304 Witt were particularly helpful in refining the library.</p>
4305 <p>The create_directories, extension, basename, and replace_extension functions
4306 were developed by Vladimir Prus. The temp_directory_path function was
4307 contributed by Jeff Flinn. David Svoboda suggested the canonical function and
4308 provided pseudo-code.</p>
4309 <p>Howard Hinnant and John Maddock reviewed a draft of the version 2 proposal, and
4310 identified a number of mistakes or weaknesses, resulting in a more polished
4312 <p>Peter Dimov suggested a single class path, with member templates to adapt to
4313 multiple string types. His idea became the basis for the version 3 path design.</p>
4314 <h2><a name="References">References</a></h2>
4315 <table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
4317 <td width="16%" valign="top">[<a name="ISO_POSIX">ISO/IEC 9945</a>]</td>
4318 <td width="84%">ISO/IEC 9945:2003, IEEE Std 1003.1-2001, and The Open Group
4319 Base Specifications, Issue 6. Also known as The Single Unix<font face="Times New Roman">®
4320 Specification, Version 3. Available from each of the organizations involved
4321 in its creation. For example, read online or download from <a href="http://www.unix.org/single_unix_specification/">www.unix.org/single_unix_specification/</a>.</font> The ISO JTC1/SC22/WG15 -
4322 POSIX homepage is <a href="http://www.open-std.org/jtc1/sc22/WG15/">www.open-std.org/jtc1/sc22/WG15/</a></td>
4325 <td width="16%" valign="top">[Abrahams]</td>
4326 <td width="84%">Dave Abrahams, Error and Exception Handling, <a href="http://www.boost.org/more/error_handling.html">www.boost.org/more/error_handling.html</a></td>
4330 <p><font size="2">© Copyright Beman Dawes, 2002, 2006, 2007, 2009, 2010, 2011</font></p>
4331 <p><font size="2">Distributed under the Boost Software License, Version 1.0. See
4333 <a href="http://www.boost.org/LICENSE_1_0.txt"><font size="2">www.boost.org/LICENSE_1_0.txt</font></a></p>
4334 <p><font size="2">Revised
4335 <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B %Y" startspan -->01 December 2015<!--webbot bot="Timestamp" endspan i-checksum="39286" --></font></p>