Skip to content

Commit 84b7662

Browse files
committed
Add exists() method in filesystem namespace as in STL's filesystem.
1 parent f45da75 commit 84b7662

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

filesystem/path.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,4 +431,9 @@ inline bool create_directories(const path& p) {
431431
#endif
432432
}
433433

434+
inline bool exists(const path& p) {
435+
return p.exists();
436+
}
437+
438+
434439
NAMESPACE_END(filesystem)

path_demo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ int main(int argc, char **argv) {
2525
cout << "some/path.ext:operator==() (unequal) = " << (path("some/path.ext") == path("another/path.ext")) << endl;
2626

2727
cout << "nonexistant:exists = " << path("nonexistant").exists() << endl;
28+
cout << "nonexistant:exists = " << exists(path("nonexistant")) << endl;
2829
cout << "nonexistant:is_file = " << path("nonexistant").is_file() << endl;
2930
cout << "nonexistant:is_directory = " << path("nonexistant").is_directory() << endl;
3031
cout << "nonexistant:filename = " << path("nonexistant").filename() << endl;
3132
cout << "nonexistant:extension = " << path("nonexistant").extension() << endl;
3233
cout << "filesystem/path.h:exists = " << path("filesystem/path.h").exists() << endl;
34+
cout << "filesystem/path.h:exists = " << exists(path("filesystem/path.h")) << endl;
3335
cout << "filesystem/path.h:is_file = " << path("filesystem/path.h").is_file() << endl;
3436
cout << "filesystem/path.h:is_directory = " << path("filesystem/path.h").is_directory() << endl;
3537
cout << "filesystem/path.h:filename = " << path("filesystem/path.h").filename() << endl;
3638
cout << "filesystem/path.h:extension = " << path("filesystem/path.h").extension() << endl;
3739
cout << "filesystem/path.h:make_absolute = " << path("filesystem/path.h").make_absolute() << endl;
3840
cout << "../filesystem:exists = " << path("../filesystem").exists() << endl;
41+
cout << "../filesystem:exists = " << exists(path("../filesystem")) << endl;
3942
cout << "../filesystem:is_file = " << path("../filesystem").is_file() << endl;
4043
cout << "../filesystem:is_directory = " << path("../filesystem").is_directory() << endl;
4144
cout << "../filesystem:extension = " << path("../filesystem").extension() << endl;

0 commit comments

Comments
 (0)