Sign in to follow this  

Checking if an entry is a file or a directory

This topic is 4545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This applies to linux C++ programming... If I had a string containing: /var/project/something How could I determine if the entry the string describes (something) is the name of a directory or a file? I've tried opening known directories using ifstream, however even if I open a directory, all the good bits are set and it does not fail... any ideas?

Share this post


Link to post
Share on other sites
When I was writing a shell for uni, one of the things we had to do before executing a program was to see if it file existed in the specified path. We used the function 'stat'.

I'm on Win right now, but here's part of the info from the cd version of MSDN, on one of the stat structure members:

Quote:

st_mode

Bit mask for file-mode information. The _S_IFDIR bit is set if path specifies a directory; the _S_IFREG bit is set if path specifies an ordinary file or a device. User read/write bits are set according to the file’s permission mode; user execute bits are set according to the filename extension.


So, it looks like this should do well for what you need.

Share this post


Link to post
Share on other sites

This topic is 4545 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this