Connecting Tech Pros Worldwide Help | Site Map

Check directory exists c++

Newbie
 
Join Date: Jan 2007
Posts: 1
#1: Jan 5 '07
Guys,
I wrote a simple code to check the existence of a directory (in UNIX based file systems) which is working for me. Have I done it in the correct way?




Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <dirent.h>
  3.  
  4. bool DirectoryExists( const char* pzPath )
  5. {
  6.     if ( pzPath == NULL) return false;
  7.  
  8.     DIR *pDir;
  9.     bool bExists = false;
  10.  
  11.     pDir = opendir (pzPath);
  12.  
  13.     if (pDir != NULL)
  14.     {
  15.         bExists = true;    
  16.         (void) closedir (pDir);
  17.     }
  18.  
  19.     return bExists;
  20. }
  21.  
  22.  
Reply