Solved

FileAttributes.hidden problem

Posted on 2009-04-08
6
239 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

863 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