Solved

FileAttributes.hidden problem

Posted on 2009-04-08
6
245 Views
Last Modified: 2013-11-27
I have to display the attributes of a file in a lits box. I am using the attached code to get the attribute.

The problem I am getting is that even though I have set a known file to Hidden, i get the error message shown in the attached image.

If I change fi.attributes to FileAttributes, it always sets fileHidden to "False"

Can someone please enlighten me to what I am doing wrong?

(I am doing stuff like ensuring the file exists etc before testing the attributes)
Dim fi As New FileInfo(fileName)
                If fi.Attributes.Hidden() = True Then
                    fileHidden = "True"
                Else
                    fileHidden = "False"
                End If

Open in new window

fi-error.jpg
0
Comment
Question by:jindalee
  • 3
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
ID: 24096003
As the attributes enum is bitwise, you have to check if the Hidden Attribute is set this way:
Dim fileHidden As Boolean = (fi.Attributes And FileAttributes.Hidden) = FileAttributes.Hidden

Open in new window

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24096161
Try this way
        Dim fi As New FileInfo(fileName)
        If fi.Attributes = FileAttributes.Hidden Then
            fileHidden = "True"
        Else
            fileHidden = "False"
        End If

Open in new window

0
 
LVL 1

Author Closing Comment

by:jindalee
ID: 31567974
Very simple really :)
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 15

Expert Comment

by:oobayly
ID: 24096215
@jpaulino
The problem with that is that if the file has several attributes set, (fi.Attributes = FileAttributes.Hidden) == false

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24096231
That's not the easy/correct way but you should check my solution.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24096261
Opps, sorry you are right!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question