How do I tell if a string is a file or a directory?

  • Thread starter Thread starter Tom P.
  • Start date Start date
If something doesn't exist it simply doesn't exist.
How very existentialist of you.

Non-existentialist, actually...I think...therefore, I am...or maybe not.
*poof!*
 
Homer J. Simpson said:
Non-existentialist, actually...I think...therefore, I am...or maybe not.
*poof!*

Someone like Descartes (who turned the phrase "I think, therefore I am")
would say that just because you perceive the file/directory to exist doesn't
mean that it actually *does* exist. Similarly, the fact that you don't
perceive it to exist does not necessarily mean that it does not.

To state definitively that something exists (or doesn't exist) is decidedly
Existentialist. :)
 
I looked and the last guy to ask this was in 2005 and he didn't get an
answer either.

I have an application that is handling both files and directories
(like a file manager). I need to be able to determine if the string
passed in is a file or a directory.

It's not good enough to use File.Exists() since that will simply tell
me the file is not a real file on the harddrive, not whether it
properly represents a file. Also, checking the FileInfo.Extension
doesn't help anymore because files don't require extensions. I've
tried FileInfo.Length (get FileNotFoundException which is the same as
Exists above). I've tried everything I can think of and I can't come
up with anything.

Thanks for any help you can give.

Tom Padilla

...

if (Directory.Exists(path))
{
// it HAS to be a directory; files are NOT directories
}
else if (File.Exists(path))
{
// we know it is a file since directories were already handled.
}

What's seems to be the confusion?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top