Rated
Read 17,630 times
Related Categories
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
James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.
Comments
|