none
How to determine if a folder is normal RRS feed

  • Question

  • Hello,

    I am populating a Treeview with drives and folders. When I add nodes with folders for a given drive, I do not want any system folders, hidden folders, etc.

    It is my understanding that the "Normal" attribute is assigned to folders that have no special attributes. When I run the following code (it's test code), I always get false.

        Private Sub TreeView1_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles TreeView1.NodeMouseClick

            Dim att As FileAttributes
            Dim finfo As DirectoryInfo
            Dim s As String

            finfo = New DirectoryInfo(e.Node.Tag)
            att = finfo.Attributes
            s = "False"
            If att = FileAttributes.Normal Then
                s = "True"
            End If
            TextBox1.Text = e.Node.Tag + " " + s

        End Sub

    How can I just get folders with no special attributes?

    Thanks

    Saturday, January 31, 2015 3:25 AM

Answers

  • A directory can have other good special attributes, such as “Compressed”, “NotContentIndexed”, etc. It also always has the “Directory” attribute.

    If you want to exclude hidden, read-only and system files, then try this:

    Dim is_normal As Boolean = (finfo.Attributes And (FileAttributes.Hidden Or FileAttribute.ReadOnly Or FileAttribute.System)) = 0
    
    s = If(is_normal, "False", "True")
    
    . . .

    Since Attributes is a combination of values (flags), you cannot use just an '=' to check an attribute.


    • Edited by Viorel_MVP Saturday, January 31, 2015 10:50 AM
    • Marked as answer by Ralph65 Thursday, February 5, 2015 12:26 AM
    Saturday, January 31, 2015 10:48 AM

All replies

  • A directory can have other good special attributes, such as “Compressed”, “NotContentIndexed”, etc. It also always has the “Directory” attribute.

    If you want to exclude hidden, read-only and system files, then try this:

    Dim is_normal As Boolean = (finfo.Attributes And (FileAttributes.Hidden Or FileAttribute.ReadOnly Or FileAttribute.System)) = 0
    
    s = If(is_normal, "False", "True")
    
    . . .

    Since Attributes is a combination of values (flags), you cannot use just an '=' to check an attribute.


    • Edited by Viorel_MVP Saturday, January 31, 2015 10:50 AM
    • Marked as answer by Ralph65 Thursday, February 5, 2015 12:26 AM
    Saturday, January 31, 2015 10:48 AM
  • Thanks!

    Ralph

    Thursday, February 5, 2015 12:46 AM