Possible Duplicate:
.NET How to check if path is a file and not a directory?
Can anyone think of a good way of telling whether a file system object path equates to a a file or a directory?
I did have the following method:
public static bool PathIsFile(this string fullPath)
{
return (Path.GetExtension(fullPath).Length > 0);
}
But some files have no extension and some directories have a dot in their name so this is not cutting it.
There’s no way of knowing just from a string analysis that something is a file or a directory, since, as you noted,
might be either a directory or a file.
You’ll have to call something like
System.IO.Directory.Exists()orSystem.IO.File.GetAttributes()to test.