JURASOURCE | WEBLOG | |
 

 

Like, uh, whatever, I guess

 

 
  Wednesday, June 09, 2004
 
    [3:58:45 PM]

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
}


More information:


    |
Comments: Post a Comment
 
 


ARCHIVES
 
November 2003
January 2004
February 2004
March 2004
April 2004
May 2004
June 2004
 
     

This page is powered by Blogger. Isn't yours?  Weblog Commenting and Trackback by HaloScan.com