We help IT Professionals succeed at work.

Quick Question on File Attributes

stev0931
stev0931 asked
on
Medium Priority
246 Views
Last Modified: 2010-04-23
How do I make the below work?  (hopfully, a solution that doesn't involve much more code than below)

Dim FileAtt As IO.FileAttributes = IO.File.GetAttributes("c:\somefile.txt")
If FileAtt = IO.FileAttributes.Hidden Then fileishidden = True
Comment
Watch Question

Author

Commented:
Note that it is the second line that does not work

Commented:
try this

If FileAtt.Hidden Then fileishidden = True
Commented:
or this
If FileAtt And IO.FileAttributes.Hidden Then fileishidden = True

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
Hi stev0931;

You will need to do it this way.

        Dim FileAtt As IO.FileAttributes = IO.File.GetAttributes("c:\Temp\TestFile.txt")
        If (FileAtt And IO.FileAttributes.Hidden) = IO.FileAttributes.Hidden Then fileishidden = True


Fernando
Commented:
what about in a single line:

fileishidden = (IO.File.GetAttributes("c:\Temp\TestFile.txt")  And IO.FileAttributes.Hidden) <> 0

or shorter (faster)

fileishidden = cbool (IO.File.GetAttributes("c:\Temp\TestFile.txt")  And IO.FileAttributes.Hidden)

have fun, Jack.net
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.