En complément des fonctions SetAttr et GetAttr, ces fonctions de l'API Windows permettent de modifier ou de lire les attributs d'un fichier, non accessibles par VB6 :
Private Const FILE_ATTRIBUTE_READONLY As Long = &H1 'Fichier en lecture seule.
Private Const FILE_ATTRIBUTE_HIDDEN As Long = &H2 'Fichier caché.
Private Const FILE_ATTRIBUTE_SYSTEM As Long = &H4 'Fichier système.
Private Const FILE_ATTRIBUTE_DIRECTORY As Long = &H10 'L'élément est un répertoire.
Private Const FILE_ATTRIBUTE_ARCHIVE As Long = &H20 'Le fichier a l'attribut archive.
Private Const FILE_ATTRIBUTE_NORMAL As Long = &H80 'Le fichier n'a pas d'attribut.
Private Const FILE_ATTRIBUTE_TEMPORARY As Long = &H100 'Fichier temporaire.
Private Const FILE_ATTRIBUTE_COMPRESSED As Long = &H800 'Fichier (répertoire) compressé.
Private Const FILE_ATTRIBUTE_ENCRYPTED As Long = &H4000 ' Fichier crypté
Private Declare Function SetFileAttributes Lib "kernel32" Alias "SetFileAttributesA" _
(ByVal lpFileName As String, ByVal dwFileAttributes As Long) As Long
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" _
(ByVal lpFileName As String) As Long
Modifier les attributs d'un fichier :
Private Sub Command1_Click()
MsgBox SetFileAttributes("C:\str.txt", FILE_ATTRIBUTE_SYSTEM)
End Sub
Lire les attributs d'un fichier :
If GetFileAttributes("C:\test.ini") And FILE_ATTRIBUTE_ENCRYPTED Then MsgBox "Fichier crypté"