Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ - Determining if directory (not a file) exists in Linux [duplicate]

Tags:

How would I determine if a directory (not a file) existed using C++ in Linux? I tried using the stat() function but it returned positive when a file was found. I only want to find if the inputted string is a directory, not something else.

like image 372
daxvena Avatar asked Feb 12 '11 21:02

daxvena


1 Answers

According to man(2) stat you can use the S_ISDIR macro on the st_mode field:

bool isdir = S_ISDIR(st.st_mode); 

Side note, I would recommend using Boost and/or Qt4 to make cross-platform support easier if your software can be viable on other OSs.

like image 85
OneOfOne Avatar answered Sep 20 '22 02:09

OneOfOne