Add directory_exists

This commit is contained in:
Adrià Arrufat 2022-04-03 00:34:17 +09:00 committed by Davis E. King
parent 9bb1b6f712
commit 23c74af872
6 changed files with 43 additions and 4 deletions

View File

@ -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 (
@ -116,6 +133,3 @@ namespace dlib
}
#endif // DLIB_DIR_NAV_EXTENSIONs_CPP_

View File

@ -19,6 +19,12 @@ namespace dlib
const std::string& filename
);
// ----------------------------------------------------------------------------------------
bool directory_exists (
const std::string& dirname
);
// ----------------------------------------------------------------------------------------
namespace implementation_details

View File

@ -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 <typename T>

View File

@ -595,6 +595,10 @@
<name>file_exists</name>
<link>dlib/dir_nav/dir_nav_extensions_abstract.h.html#file_exists</link>
</item>
<item>
<name>directory_exists</name>
<link>dlib/dir_nav/dir_nav_extensions_abstract.h.html#directory_exists</link>
</item>
<item>
<name>select_oldest_file</name>
<link>dlib/dir_nav/dir_nav_extensions_abstract.h.html#select_oldest_file</link>

View File

@ -13,6 +13,7 @@
<current>
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.

View File

@ -1094,6 +1094,7 @@
<term file="dlib/dir_nav/dir_nav_extensions_abstract.h.html" name="get_files_in_directory_tree" include="dlib/dir_nav.h"/>
<term file="dlib/dir_nav/dir_nav_extensions_abstract.h.html" name="get_parent_directory" include="dlib/dir_nav.h"/>
<term file="dlib/dir_nav/dir_nav_extensions_abstract.h.html" name="file_exists" include="dlib/dir_nav.h"/>
<term file="dlib/dir_nav/dir_nav_extensions_abstract.h.html" name="directory_exists" include="dlib/dir_nav.h"/>
<term file="dlib/dir_nav/dir_nav_extensions_abstract.h.html" name="select_oldest_file" include="dlib/dir_nav.h"/>
<term file="dlib/dir_nav/dir_nav_extensions_abstract.h.html" name="select_newest_file" include="dlib/dir_nav.h"/>
<term file="dlib/dir_nav/dir_nav_extensions_abstract.h.html" name="match_ending" include="dlib/dir_nav.h"/>