Checking if an entry is a file or a directory

Started by
2 comments, last by Xtremehobo 18 years, 9 months ago
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?
pixelwrench.com | [email="matt[nospam]@pixelwrench[nospam]com"]email[/email] lethalhamster: gamedev keeps taking my money, but im too lazy to not let them
Advertisement
boost::filesystem has functions to do that.
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.
[size="2"][size=2]Mort, Duke of Sto Helit: NON TIMETIS MESSOR -- Don't Fear The Reaper
@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]
pixelwrench.com | [email="matt[nospam]@pixelwrench[nospam]com"]email[/email] lethalhamster: gamedev keeps taking my money, but im too lazy to not let them

This topic is closed to new replies.

Advertisement