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
-
VB6, SQL 2005 & DMO
by elajaunie3 (1 replies)
-
sending sms from pc
by sriraj20074 (0 replies)
-
Automating Excel from VB6.0
by epurdy (0 replies)
-
VB6 system conversion using VBA to Word 2007
by b.macgregor@vodamail.co.za (0 replies)
-
video not working with visual basic
by Jupiter 2 (9 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.