| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
| Classes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| File types | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <experimental/filesystem> | ||
bool exists( file_status s) | (1) | (filesystem TS) |
bool exists(const path& p); bool exists(const path& p, error_code& ec) | (2) | (filesystem TS) |
Checks if the given file status or path corresponds to an existing file or directory.
Contents |
| s | - | file status to check |
| p | - | path to examine |
| ec | - | out-parameter for error reporting in the non-throwing overload |
true if the given path or file status corresponds to an existing file or directory,false otherwise.
The information provided by this function is usually also provided as a byproduct of directory iteration. During directory iteration, callingexists(*iterator) is less efficient thanexists(iterator->status()).
#include <cstdint>#include <experimental/filesystem>#include <fstream>#include <iostream>namespace fs= std::experimental::filesystem; void demo_exists(const fs::path& p, fs::file_status s= fs::file_status{}){std::cout<< p;if(fs::status_known(s)? fs::exists(s): fs::exists(p))std::cout<<" exists\n";elsestd::cout<<" does not exist\n";} int main(){ fs::create_directory("sandbox");std::ofstream("sandbox/file");// create regular file fs::create_symlink("non-existing","sandbox/symlink"); demo_exists("sandbox");for(auto it= fs::directory_iterator("sandbox"); it!= fs::directory_iterator();++it) demo_exists(*it, it->status());// use cached status from directory entry fs::remove_all("sandbox");}
Output:
"sandbox" exists"sandbox/file" exists"sandbox/symlink" does not exist
| determines file attributes determines file attributes, checking the symlink target (function)[edit] | |
| represents file type and permissions (class)[edit] | |
| cached status of the file designated by this directory entry cached symlink_status of the file designated by this directory entry (public member function of std::experimental::filesystem::directory_entry)[edit] |