Distinguish between a File and a Directory in .NET
Whilst writing some code to manage new DasBlog releases for a number of DasBlog instances, I became a bit stuck on how to distinguish between a file and a directory when using the FileInfo class.
It turns out that it's actually pretty easy.
An instance of FileInfo has an Attributes property, and to check whether the instance refers to a directory you need to do a bitwise AND, like so:
if ( ( file.Attributes & FileAttributes.Directory ) == FileAttributes.Directory )
// Its a directory