Solved

FileAttributes.hidden problem

Posted on 2009-04-08
6
232 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now