diff --git a/include/GTools.hpp b/include/GTools.hpp index 1fce8fc..75fa0a7 100644 --- a/include/GTools.hpp +++ b/include/GTools.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GTools.hpp - GammaLib tools * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2013 by Juergen Knoedlseder * + * copyright (C) 2008-2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -88,6 +88,7 @@ namespace gammalib { const double& epivot, const double& gamma); bool file_exists(const std::string& filename); + bool dir_exists(const std::string& dirname); bool is_infinite(const double& x); bool is_notanumber(const double& x); bool contains(const std::string& str, diff --git a/pyext/GTools.i b/pyext/GTools.i index fa1f5d0..b24f8ed 100644 --- a/pyext/GTools.i +++ b/pyext/GTools.i @@ -1,7 +1,7 @@ /*************************************************************************** * GTools.hpp - GammaLib tools * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2013 by Juergen Knoedlseder * + * copyright (C) 2008-2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -83,6 +83,7 @@ namespace gammalib { const double& epivot, const double& gamma); bool file_exists(const std::string& filename); + bool dir_exists(const std::string& dirname); bool is_infinite(const double& x); bool is_notanumber(const double& x); } diff --git a/src/support/GTools.cpp b/src/support/GTools.cpp index 3e4e619..36faa98 100644 --- a/src/support/GTools.cpp +++ b/src/support/GTools.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GTools.cpp - GammaLib tools * * ----------------------------------------------------------------------- * - * copyright (C) 2008-2013 by Juergen Knoedlseder * + * copyright (C) 2008-2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -825,6 +825,35 @@ bool gammalib::file_exists(const std::string& filename) return result; } + +/***********************************************************************//** + * @brief Checks if directory exists + * + * @param[in] dirname Directory name. + * + * Checks if a directory exists. + ***************************************************************************/ +bool gammalib::dir_exists(const std::string& dirname) +{ + // Initialise result + bool result = false; + + // Allocate file information structure + struct stat info; + + // Get file information structure + int ret = stat(dirname.c_str(), &info); + + // Check if we have a directory + if (ret == 0 && S_ISDIR(info.st_mode)) { + result = true; + } + + // Return result + return result; +} + + /***********************************************************************//** * @brief Checks if a substring is in a string *