By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,896 Members | 2,002 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,896 IT Pros & Developers. It's quick & easy.

DirectoryInfo and FileAttributes

P: n/a
I'm trying to compare DirectoryInfo.Attributes to FileAttributes like so:
// result returning
// Directory | Archive
DirectoryInfo info = new DirectoryInfo(this.folderFullName);
if (info.Attributes != FileAttributes.Directory)
{
throw new FoundFileException(this.folderFullName);
}

for some reason it returns true. why?
i eventually had to add a line after the info declaration like so.
string[] nfo = info.Attributes.ToString().Split(',');

and my new test will be like:
if(nfo[0] != FileAttributes.Directory.ToString() )
{
throw new FoundFileException(this.folderFullName);
}
Why is this the case???

Sep 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
DirectoryInfo info = new DirectoryInfo(this.folderFullName);
if (info.Attributes != FileAttributes.Directory)
{
throw new FoundFileException(this.folderFullName);
}

for some reason it returns true. why?
Because FileAttributes is a Flags enum and the Attribute property can
return a combination of multiple values from that enum. So rather than
testign for equality, you can test for the Directory flag like this

if ((info.Attributes & FileAttributes.Directory) != 0)
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.