TROUVER LE TYPE DE FICHIER EX:"C:\abc.zip"->"Fichier Winzip"

Nico - 10 août 2001 à 21:18
 Makabey - 11 août 2001 à 00:38
Existe -t-il une fonction qui permette de trouver le type de fichier, par exemple une fonction à laquelle je donne l'argument "C:\abc.zip" me renverrait "Fichier Winzip"?

2 réponses

J'ai fait ceci à l'aide d'une Form, un Command, un TextBox, un Common Dialog et la classe cRegistry de http://vbaccelerator.com :

Private Sub Command1_Click()
  'Code testé VB6
  Dim RegBot As New cRegistry
  Dim lPos As Long

  With CommonDialog1
    .CancelError = True
    .DialogTitle = "Lire type fichier"
    .Filter = "Tous (*.*)|*.*"
    .FilterIndex = 1
    .Flags = cdlOFNPathMustExist Or cdlOFNFileMustExist Or cdlOFNHideReadOnly
    .InitDir = "c:\my documents"
    .ShowOpen
    
    
    'Pomper l'extension
    lPos = InStrRev(.FileTitle, ".")
    If lPos = 0 Then Exit Sub
    
    
    'Type étape 1
    RegBot.ClassKey = HKEY_CLASSES_ROOT
    RegBot.SectionKey = Right$(.FileTitle, Len(.FileTitle) - lPos + 1)
    RegBot.ValueKey = ""
    RegBot.ValueType = REG_SZ
    
    
    'Type étape 2
    RegBot.ClassKey = HKEY_CLASSES_ROOT
    RegBot.SectionKey = RegBot.Value
    RegBot.ValueKey = ""
    RegBot.ValueType = REG_SZ
    
    Text1 = RegBot.Value
  End With
End Sub
0
J'ai fait ceci à l'aide d'une Form, un Command, un TextBox, un Common Dialog et la classe cRegistry de http://vbaccelerator.com :

Private Sub Command1_Click()
  'Code testé VB6
  Dim RegBot As New cRegistry
  Dim lPos As Long

  With CommonDialog1
    .CancelError = True
    .DialogTitle = "Lire type fichier"
    .Filter = "Tous (*.*)|*.*"
    .FilterIndex = 1
    .Flags = cdlOFNPathMustExist Or cdlOFNFileMustExist Or cdlOFNHideReadOnly
    .InitDir = "c:\my documents"
    .ShowOpen
    
    
    'Pomper l'extension
    lPos = InStrRev(.FileTitle, ".")
    If lPos = 0 Then Exit Sub
    
    
    'Type étape 1
    RegBot.ClassKey = HKEY_CLASSES_ROOT
    RegBot.SectionKey = Right$(.FileTitle, Len(.FileTitle) - lPos + 1)
    RegBot.ValueKey = ""
    RegBot.ValueType = REG_SZ
    
    
    'Type étape 2
    RegBot.ClassKey = HKEY_CLASSES_ROOT
    RegBot.SectionKey = RegBot.Value
    RegBot.ValueKey = ""
    RegBot.ValueType = REG_SZ
    
    Text1 = RegBot.Value
  End With
End Sub
0
Rejoignez-nous