File Attributes

This example demonstrates retrieving file attributes such as ReadOnly, Archive, System etc. Add a command button called cmdGet, and a textbox called txtFile. Add the code below, and run your project. Enter a filename into txtFile, and click the button to retrieve the properties.

Private Sub cmdGet_Click()
    GetFileInfo (txtfile)
End Sub

Sub GetFileInfo(sFile As String)
    Dim sFileAttrib As Long
    Dim sFileInfo As String
    sFileAttrib = GetAttr(sFile)
    ' Get Attibutes and fill attribute string
    If (sFileAttrib And vbReadOnly) = vbReadOnly Then
        sFileInfo = sFileInfo & "Read Only"
    End If
    If (sFileAttrib And vbArchive) = vbArchive Then
        sFileInfo = sFileInfo & " Archive"
    End If
    If (sFileAttrib And vbNormal) = vbNormal Then
        sFileInfo = sFileInfo & " Normal"
    End If
    If (sFileAttrib And vbSystem) = vbSystem Then
        sFileInfo = sFileInfo & " System"
    End If
    If (sFileAttrib And vbHidden) = vbHidden Then
        sFileInfo = sFileInfo & " Hidden"
    End If
    If (sFileAttrib And vbDirectory) = vbDirectory Then
        sFileInfo = sFileInfo & " Directory"
    End If
    MsgBox sFile & " has the following properties: " & sFileInfo
End Sub

You might also like...

Comments

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.” - Alan Kay