Library code snippets
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
Related articles
Related discussion
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
-
listbox scrollbar
by Dennijr (10 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
Good code works for me BUT I do get some strange results.. some files return an unknown attribute. When doing a simply x = getattr(filename) some are over 8000??? Any ideas what attribute this is?
OS=winXP
s/w=VB6
This thread is for discussions of File Attributes.