AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

Retrieving the File Attributes/

This tips demonstrates how to use the GetFileAttributes API function to retrieve the attributes of a file.  The attributes include whether the file is read-only or marked as a system or hidden file.

Module Code

Add the following code to a module:

Declare Function GetFileAttributes Lib "kernel32" _
Alias "GetFileAttributesA" _
(ByVal lpFileName As String) As Long

Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_SYSTEM = &H4

Form Code

Add a command button to a form with the following code:

Private Sub Command1_Click()

Dim FileName As String, Attributes As Long

'Use the filename you want
FileName = "C:\MSDOS.SYS"

'Get the attributes with the GetFileAttributes API
Attributes& = GetFileAttributes(FileName)

'Check the returned value for the different
'attributes using the AND-Operator.

Print "FileName: " & FileName & ", Attributes: " & Attributes&
Print
Print "hidden:" & vbTab & vbTab & _
CBool(Attributes& And FILE_ATTRIBUTE_HIDDEN)
Print "system:" & vbTab & vbTab & _
CBool(Attributes& And FILE_ATTRIBUTE_SYSTEM)
Print "archive:" & vbTab & vbTab & _
CBool(Attributes& And FILE_ATTRIBUTE_ARCHIVE)
Print "readonly:" & vbTab & _
CBool(Attributes& And FILE_ATTRIBUTE_READONLY)
End Sub

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/