Quick Question on File Attributes

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
stev0931Asked:
Who is Participating?
 
Fernando SotoRetiredCommented:
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
0
 
stev0931Author Commented:
Note that it is the second line that does not work
0
 
appariCommented:
try this

If FileAtt.Hidden Then fileishidden = True
0
 
appariCommented:
or this
If FileAtt And IO.FileAttributes.Hidden Then fileishidden = True
0
 
jrschererCEOCommented:
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
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.

All Courses

From novice to tech pro — start learning today.