Sign in to follow this  
Xtremehobo

Checking if an entry is a file or a directory

Recommended Posts

Xtremehobo    820
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
Endar    668
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
Xtremehobo    820
@Endar: Thanks, that's exactly what I needed!

@SiCrane: I'm now downloading boost, I think it'll work niceley for my other project [smile]

Share this post


Link to post
Share on other sites

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