*** Attribut de fichiers ***

browser64 Messages postés 112 Date d'inscription dimanche 24 avril 2005 Statut Membre Dernière intervention 5 décembre 2010 - 2 déc. 2006 à 03:25
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 - 2 déc. 2006 à 10:40
Bonjour,

Voila j'ai un fichier dans le repertoire de mon windows qui se nomme  ' Lecteur carte Sim.efr '
je dois mettre ce fichier en Attribut caché et systeme.

Mon api  trouve bien portant le repertoire du windows que j'utilise mais j'ai l'attribut de mon fichier qui ne veut pas changer.    Ou se trouve l'erreur ? 

              Merci

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Sub Form_Load()
Dim result As Long
Dim Buffer As String
Dim Size As Long
Size = GetWindowsDirectory(vbNullString, 0)
Buffer = String(Size, " ")
Size = GetWindowsDirectory(Buffer, Size)
Buffer = Left(Buffer, Size)
If LCase(App.Path) = Buffer Then
If App.PrevInstance = True Then End
Else
Call SetAttr("\Lecteur carte Sim.efr", Buffer & vbHidden Or vbSystem) '''J'AI UNE ERREUR SUR CETTE LIGNE, C'EST PAS LE BUFFER QUI EST MAL MIT ?'''
End If
End Sub

3 réponses

cs_JMO Messages postés 1854 Date d'inscription jeudi 23 mai 2002 Statut Membre Dernière intervention 24 juin 2018 27
2 déc. 2006 à 05:33
 Bonjour

Exemple à adapter pour vb6.

Call ToggleArchiveBit("D:\test.log")
Function ToggleArchiveBit(filespec)
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFile(filespec)   'GetFile ou GetFolder
   MsgBox f.attributes
   'If f.attributes and 32 Then
   '   f.attributes = f.attributes - 32
   '   ToggleArchiveBit = "Bit d'archive effacé."
   'Else
   '   f.attributes = f.attributes + 32
   '   ToggleArchiveBit = "Bit d'archive défini."
   'End If
   f.attributes = 2     'f.attributes - 32
   MsgBox f.Attributes
End Function



'Constante Valeur Description
'Normal       0 Fichier normal. Aucun attribut n'est défini.
'ReadOnly     1 Fichier en lecture seule. L'attribut est lecture/écriture.
'Hidden       2 Fichier masqué. L'attribut est lecture/écriture.
'System       4 Fichier système. L'attribut est lecture/écriture.
'Volume       8 Étiquette de volume du lecteur de disque. L'attribut est lecture/écriture.
'Directory   16 Dossier ou répertoire. L'attribut est lecture seule.
'Archive     32 Le fichier a été modifié depuis la dernière copie de sauvegarde. L'attribut est lecture/écriture.
'Alias       64 Lien ou raccourci. L'attribut est lecture seule.
'Compressed 128 Fichier comprimé. L'attribut est lecture seule.



jean-marc
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
2 déc. 2006 à 10:37
salut,

pourtant en relisant même très vite, on voit ce qui cloche.....

Option Explicit
'
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As
Long
'
Private Sub Form_Load()
    Dim result As Long
    Dim Buffer As String
    Dim Size As Long
    
    Size =  GetWindowsDirectory(vbNullString, 0)
    Buffer = String(Size, " ")
    Size = GetWindowsDirectory(Buffer, Size)
    Buffer = Left(Buffer, Size)
    
    If LCase(App.Path) = Buffer Then
        If App.PrevInstance = True Then End
    Else
        Call SetAttr(Buffer & "\Lecteur carte
Sim.efr", vbHidden Or vbSystem)
    End If
End Sub

<small>Coloration
syntaxique automatique [AFCK] </small>
       

ps : quel intérêt ce test App.PrevInstance à cet endroit?
++
<hr size ="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
2 déc. 2006 à 10:40
et je lis trop vite aussi ^^ :

Size =  GetWindowsDirectory(Buffer, Size)

tu es sûr de l'utilisation de l'API ? !!!

    Dim Path as String, strSave as string
    strSave = String(200, Chr$(0))
    Path = Left$(strSave, GetWindowsDirectory(strSave, Len(strSave)))

<small>Coloration
syntaxique automatique [AFCK] </small>
       
<hr size ="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
0
Rejoignez-nous