Quick Question on File Attributes

Posted on 2006-03-19
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
Question by:stev0931

    Author Comment

    Note that it is the second line that does not work
    LVL 39

    Expert Comment

    try this

    If FileAtt.Hidden Then fileishidden = True
    LVL 39

    Assisted Solution

    or this
    If FileAtt And IO.FileAttributes.Hidden Then fileishidden = True
    LVL 62

    Accepted Solution

    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

    LVL 9

    Assisted Solution

    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,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now