Solved

FileAttributes.hidden problem

Posted on 2009-04-08
6
244 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net WebRequest Code from JSON curl 7 48
Help with preventing downloading a zip file 10 45
MailAddress in vb 4 29
Need syntax help building hyperlink 2 22
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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