By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

Check directory exists c++

P: 1
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.  
Jan 5 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.