Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

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
0
jindalee
Asked:
jindalee
  • 3
  • 2
1 Solution
 
oobaylyCommented:
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
 
Jorge PaulinoIT Pro/DeveloperCommented:
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
 
jindaleeAuthor Commented:
Very simple really :)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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

0
 
Jorge PaulinoIT Pro/DeveloperCommented:
That's not the easy/correct way but you should check my solution.
0
 
Jorge PaulinoIT Pro/DeveloperCommented:
Opps, sorry you are right!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now