Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 13th, 2012  |  syntax: None  |  size: 0.73 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Check folder path
  2. bool directory_exists( const std::string &directory )
  3. {
  4.     if( !directory.empty() )
  5.     {
  6.         if( access(directory.c_str(), 0) == 0 )
  7.         {
  8.             struct stat status;
  9.             stat( directory.c_str(), &status );
  10.             if( status.st_mode & S_IFDIR )
  11.                 return true;
  12.         }
  13.     }
  14.     // if any condition fails
  15.     return false;
  16. }
  17. bool file_exists( const std::string &filename )
  18. {
  19.     if( !filename.empty() )
  20.     {
  21.         if( access(filename.c_str(), 0) == 0 )
  22.         {
  23.            struct stat status;
  24.            stat( filename.c_str(), &status );
  25.            if( !(status.st_mode & S_IFDIR) )
  26.                return true;
  27.         }
  28.     }
  29.     // if any condition fails
  30.     return false;
  31. }