Commit 585d667622b62285d96554540076a054f612a2bc

Authored by Jürgen Knödlseder
1 parent 7c0b7939

Add gammalib::dir_exists() function.

include/GTools.hpp
1 1 /***************************************************************************
2 2 * GTools.hpp - GammaLib tools *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2013 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -88,6 +88,7 @@ namespace gammalib {
88 88 const double& epivot,
89 89 const double& gamma);
90 90 bool file_exists(const std::string& filename);
  91 + bool dir_exists(const std::string& dirname);
91 92 bool is_infinite(const double& x);
92 93 bool is_notanumber(const double& x);
93 94 bool contains(const std::string& str,
... ...
pyext/GTools.i
1 1 /***************************************************************************
2 2 * GTools.hpp - GammaLib tools *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2013 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -83,6 +83,7 @@ namespace gammalib {
83 83 const double& epivot,
84 84 const double& gamma);
85 85 bool file_exists(const std::string& filename);
  86 + bool dir_exists(const std::string& dirname);
86 87 bool is_infinite(const double& x);
87 88 bool is_notanumber(const double& x);
88 89 }
... ...
src/support/GTools.cpp
1 1 /***************************************************************************
2 2 * GTools.cpp - GammaLib tools *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2013 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -825,6 +825,35 @@ bool gammalib::file_exists(const std::string& filename)
825 825 return result;
826 826 }
827 827  
  828 +
  829 +/***********************************************************************//**
  830 + * @brief Checks if directory exists
  831 + *
  832 + * @param[in] dirname Directory name.
  833 + *
  834 + * Checks if a directory exists.
  835 + ***************************************************************************/
  836 +bool gammalib::dir_exists(const std::string& dirname)
  837 +{
  838 + // Initialise result
  839 + bool result = false;
  840 +
  841 + // Allocate file information structure
  842 + struct stat info;
  843 +
  844 + // Get file information structure
  845 + int ret = stat(dirname.c_str(), &info);
  846 +
  847 + // Check if we have a directory
  848 + if (ret == 0 && S_ISDIR(info.st_mode)) {
  849 + result = true;
  850 + }
  851 +
  852 + // Return result
  853 + return result;
  854 +}
  855 +
  856 +
828 857 /***********************************************************************//**
829 858 * @brief Checks if a substring is in a string
830 859 *
... ...