Jump to content
  • Advertisement
Sign in to follow this  

Checking if an entry is a file or a directory

This topic is 4703 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
Advertisement
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
@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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!