From 23c74af872c85df887a3221c92c6559bafed798d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Sun, 3 Apr 2022 00:34:17 +0900 Subject: [PATCH] Add directory_exists --- dlib/dir_nav/dir_nav_extensions.cpp | 22 ++++++++++++++++++---- dlib/dir_nav/dir_nav_extensions.h | 6 ++++++ dlib/dir_nav/dir_nav_extensions_abstract.h | 13 +++++++++++++ docs/docs/api.xml | 4 ++++ docs/docs/release_notes.xml | 1 + docs/docs/term_index.xml | 1 + 6 files changed, 43 insertions(+), 4 deletions(-) diff --git a/dlib/dir_nav/dir_nav_extensions.cpp b/dlib/dir_nav/dir_nav_extensions.cpp index db05e4cc4..8f40d5bcf 100644 --- a/dlib/dir_nav/dir_nav_extensions.cpp +++ b/dlib/dir_nav/dir_nav_extensions.cpp @@ -51,6 +51,23 @@ namespace dlib } } +// ---------------------------------------------------------------------------------------- + + bool directory_exists ( + const std::string& dirname + ) + { + try + { + dlib::directory temp(dirname); + return true; + } + catch (directory::dir_not_found&) + { + return false; + } + } + // ---------------------------------------------------------------------------------------- directory get_parent_directory ( @@ -70,7 +87,7 @@ namespace dlib return directory(); std::string::size_type pos = f.full_name().find_last_of("\\/"); - + if (pos == std::string::npos) return directory(); @@ -116,6 +133,3 @@ namespace dlib } #endif // DLIB_DIR_NAV_EXTENSIONs_CPP_ - - - diff --git a/dlib/dir_nav/dir_nav_extensions.h b/dlib/dir_nav/dir_nav_extensions.h index 93dde1159..16e2f7aa9 100644 --- a/dlib/dir_nav/dir_nav_extensions.h +++ b/dlib/dir_nav/dir_nav_extensions.h @@ -19,6 +19,12 @@ namespace dlib const std::string& filename ); +// ---------------------------------------------------------------------------------------- + + bool directory_exists ( + const std::string& dirname + ); + // ---------------------------------------------------------------------------------------- namespace implementation_details diff --git a/dlib/dir_nav/dir_nav_extensions_abstract.h b/dlib/dir_nav/dir_nav_extensions_abstract.h index 4aa6cc4f2..e4056fe39 100644 --- a/dlib/dir_nav/dir_nav_extensions_abstract.h +++ b/dlib/dir_nav/dir_nav_extensions_abstract.h @@ -23,6 +23,19 @@ namespace dlib - returns false !*/ +// ---------------------------------------------------------------------------------------- + + bool directory_exists ( + const std::string& dirname + ); + /*! + ensures + - if (a directory with the given filename exists) then + - returns true + - else + - returns false + !*/ + // ---------------------------------------------------------------------------------------- template diff --git a/docs/docs/api.xml b/docs/docs/api.xml index 2d6811b44..e49203c08 100644 --- a/docs/docs/api.xml +++ b/docs/docs/api.xml @@ -595,6 +595,10 @@ file_exists dlib/dir_nav/dir_nav_extensions_abstract.h.html#file_exists + + directory_exists + dlib/dir_nav/dir_nav_extensions_abstract.h.html#directory_exists + select_oldest_file dlib/dir_nav/dir_nav_extensions_abstract.h.html#select_oldest_file diff --git a/docs/docs/release_notes.xml b/docs/docs/release_notes.xml index f033bb505..ba15d6c54 100644 --- a/docs/docs/release_notes.xml +++ b/docs/docs/release_notes.xml @@ -13,6 +13,7 @@ New Features and Improvements: - Added Beta distribution to dlib::rand. + - Added directory_exists. - Deep learning tooling: - Added ReOrg layer. - Added visitor to draw network architectures using the DOT language. diff --git a/docs/docs/term_index.xml b/docs/docs/term_index.xml index 2c875b897..4f746a26c 100644 --- a/docs/docs/term_index.xml +++ b/docs/docs/term_index.xml @@ -1094,6 +1094,7 @@ +