I want a (preferrably POSIX-compatible) way to tell if a file is a directory under Windows and Linux, other than access() and stat(). Nothing has turned up so far . . .
I want a (preferrably POSIX-compatible) way to tell if a file is a directory under Windows and Linux, other than access() and stat(). Nothing has turned up so far . . .
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Try to open it for reading. If it's not there, fopen should fail. Of course, on a crappy OS where you can't open files already in use, it'll fail too, so I suppose that won't tell you for sure in that case. :P
Quzah.
Hope is the first step on the road to disappointment.
But stat() is POSIX, so what's your question?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well, I want a fast function if I can get one. I thought stat() was rather slow.
The only other idea I had was to try to chdir() to the filename . . . if it fails, it's not a directory.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
You "think" it's slow based on what?
By actually trying it?
You're messing with things on disk, which despite their impressive sounding speeds are pitifully slow compared to the speed between processor and memory.
Or decide that performance is more important, and write a wrapper myIsDirectory() function around something more OS specific.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I don't know if this is gonna help but recently (in unix) I used read() on a file descriptor. Then if it returned an error, and errno was EISDIR (or something like that, then I knew it was a directory.
"So you're one of those condescending UNIX computer users?"
"Here's a nickel, kid. Get yourself a better computer."