cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : UNIX/Linux Programming : path name
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

post  path name

theChameleon (9)
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
jsmith (379)
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 );
}
|
Zaita (1138)
You could also use Boost::FileSystem :)
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us