[fs.op.status]

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

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

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

#### 31.12.13.36 Status [fs.op.status]

[ð](#lib:status)

`file_status filesystem::status(const path& p);
`

[1](#1)

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

*Effects*: As if by:error_code ec;
file_status result = status(p, ec);if (result.type() == file_type::none)throw filesystem_error(*implementation-supplied-message*, p, ec);return result;

[2](#2)

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

*Returns*: See above[.](#2.sentence-1)

[3](#3)

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

*Throws*: filesystem_error[.](#3.sentence-1)

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

result values of file_status(file_type​::​not_found) and file_status(file_type​::​unknown) are not considered failures and do not
 cause an exception to be thrown[.](#3.sentence-2)

â *end note*]

[ð](#lib:status_)

`file_status filesystem::status(const path& p, error_code& ec) noexcept;
`

[4](#4)

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

*Effects*: If possible, determines the attributes
 of the file p resolves to, as if by using POSIX stat to obtain a POSIX struct stat[.](#4.sentence-1)

If, during attribute determination, the underlying file system API reports
 an error, sets ec to indicate the specific error reported[.](#4.sentence-2)

Otherwise, ec.clear()[.](#4.sentence-3)

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

This allows users to inspect the specifics of underlying
 API errors even when the value returned by status is not file_status(file_type​::​none)[.](#4.sentence-4)

â *end note*]

[5](#5)

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

Let prms denote the result of (m & perms​::​mask),
where m is determined as if by converting the st_mode member
of the obtained struct stat to the type perms[.](#5.sentence-1)

[6](#6)

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

*Returns*: 

- [(6.1)](#6.1)

  If ec != error_code():
  * [(6.1.1)](#6.1.1)

      If the specific error indicates that p cannot be resolved
 because some element of the path does not exist, returns file_status(file_type​::​not_found)[.](#6.1.1.sentence-1)

  * [(6.1.2)](#6.1.2)

      Otherwise, if the specific error indicates that p can be resolved
 but the attributes cannot be determined, returns file_status(file_type​::​unknown)[.](#6.1.2.sentence-1)

  * [(6.1.3)](#6.1.3)

      Otherwise, returns file_status(file_type​::​none)[.](#6.1.3.sentence-1)

  [*Note [3](#note-3)*:
  These semantics distinguish between p being known not to exist, p existing but not being able to determine its attributes,
 and there being an error that prevents even knowing if p exists[.](#6.1.sentence-2)
  These
 distinctions are important to some use cases[.](#6.1.sentence-3)
 â *end note*]

- [(6.2)](#6.2)

  Otherwise,
  * [(6.2.1)](#6.2.1)

      If the attributes indicate a regular file, as if by POSIX S_ISREG,
 returns file_status(file_type​::​regular, prms)[.](#6.2.1.sentence-1)
      [*Note [4](#note-4)*:
      file_type​::​regular implies appropriate [<fstream>](fstream.syn#header:%3cfstream%3e "31.10.1 Header <fstream> synopsis [fstream.syn]") operations
 would succeed, assuming no hardware, permission, access, or file system
 race errors[.](#6.2.1.sentence-2)
      Lack of file_type​::​regular does not necessarily imply [<fstream>](fstream.syn#header:%3cfstream%3e "31.10.1 Header <fstream> synopsis [fstream.syn]") operations would fail on a directory[.](#6.2.1.sentence-3)
 â *end note*]

  * [(6.2.2)](#6.2.2)

      Otherwise, if the attributes indicate a directory, as if by POSIX S_ISDIR, returns file_status(file_type​::​directory, prms)[.](#6.2.2.sentence-1)
      [*Note [5](#note-5)*:
      file_type​::​directory implies that calling directory_iterator(p) would succeed[.](#6.2.2.sentence-2)
 â *end note*]

  * [(6.2.3)](#6.2.3)

      Otherwise, if the attributes indicate a block special file, as if by
 POSIX S_ISBLK, returns file_status(file_type​::​block, prms)[.](#6.2.3.sentence-1)

  * [(6.2.4)](#6.2.4)

      Otherwise, if the attributes indicate a character special file, as if
 by POSIX S_ISCHR, returns file_status(file_type​::​character, prms)[.](#6.2.4.sentence-1)

  * [(6.2.5)](#6.2.5)

      Otherwise, if the attributes indicate a fifo or pipe file, as if by
 POSIX S_ISFIFO, returns file_status(file_type​::​fifo, prms)[.](#6.2.5.sentence-1)

  * [(6.2.6)](#6.2.6)

      Otherwise, if the attributes indicate a socket, as if by POSIX S_ISSOCK, returns file_status(file_type​::​socket, prms)[.](#6.2.6.sentence-1)

  * [(6.2.7)](#6.2.7)

      Otherwise, if the attributes indicate an implementation-defined
 file type ([[fs.enum.file.type]](fs.enum.file.type "31.12.8.2 Enum class file_­type")),
 returns file_status(file_type​::​*A*, prms),
 where *A* is the constant for the implementation-defined file type[.](#6.2.7.sentence-1)

  * [(6.2.8)](#6.2.8)

      Otherwise, returns file_status(file_type​::​unknown, prms)[.](#6.2.8.sentence-1)

[7](#7)

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

*Remarks*: If a symbolic link is encountered during pathname resolution,
 pathname resolution continues using the contents of the symbolic link[.](#7.sentence-1)
