Link to home
Start Free TrialLog in
Avatar of jindalee
jindalee

asked on

FileAttributes.hidden problem

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
ASKER CERTIFIED SOLUTION
Avatar of oobayly
oobayly
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of jindalee
jindalee

ASKER

Very simple really :)
@jpaulino
The problem with that is that if the file has several attributes set, (fi.Attributes = FileAttributes.Hidden) == false

That's not the easy/correct way but you should check my solution.
Opps, sorry you are right!