path name

hello, what functions do i have to use to check the validity of a directory path the user entered?

example check that "/usr/" is ok but "wegdfhoiehgboarj" is not.

thanks.
Last edited on
man 2 stat

Use stat on the path. If stat returns 0, then check st_mode to see if the statted thing
is a directory:

1
2
3
4
5
6
7
8
9
10
11
12
#include <sys/types.h>
#Include <sys/stat.h>
#include <unistd.h>

bool CheckPath( const char* userPath ) {
   struct stat statBuf;

   if( stat( userPath, &statBuf ) < 0 ) 
         return false;

   return S_ISDIR( statBuf.st_mode );
}
You could also use Boost::FileSystem :)
Topic archived. No new replies allowed.