IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

deziper un fichier avec 7zip


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Avatar de tamtam64
    Homme Profil pro
    stagiaire developpement vba
    Inscrit en
    Mai 2012
    Messages
    456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : stagiaire developpement vba
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2012
    Messages : 456
    Billets dans le blog
    17
    Par défaut deziper un fichier avec 7zip
    Bonjour,

    Je souhaiterais une explication si possible sur un code que je ne maitrise pas et que je voudrais comprendre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    Public Nom As String
     
     
    Declare Function OpenProcess Lib "kernel32" _
                                 (ByVal dwDesiredAccess As Long, _
                                  ByVal bInheritHandle As Long, _
                                  ByVal dwProcessId As Long) As Long
     
    Declare Function GetExitCodeProcess Lib "kernel32" _
                                        (ByVal hProcess As Long, _
                                         lpExitCode As Long) As Long
     
    Public Const PROCESS_QUERY_INFORMATION = &H400
    Public Const STILL_ACTIVE = &H103
     
    Public Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
     
        Dim hProg As Long
        Dim hProcess As Long, ExitCode As Long
     
        If IsMissing(WindowState) Then WindowState = 1
        hProg = Shell(PathName, WindowState)
     
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
        Do
     
            GetExitCodeProcess hProcess, ExitCode
            DoEvents
     
        Loop While ExitCode = STILL_ACTIVE
    End Sub
     
    Sub Dezipper()
     
        Dim CheminZip As String
        Dim DossierUnZip As String
        Dim FichierZip As Variant, ShellStr As String
     
        CheminZip = "C:\program files\7-Zip\"
        If Right(CheminZip, 1) <> "\" Then
            CheminZip = CheminZip & "\"
        End If
     
        If Dir(CheminZip & "7z.exe") = "" Then
            Exit Sub
        End If
     
     
        DossierUnZip = "C:\Divers\Archives\"
        FichierZip = "C:\Divers\Archives\" & Nom
        ShellStr = CheminZip & "7z.exe x -aoa -r" _
                 & " " & Chr(34) & FichierZip & Chr(34) _
                 & " -o" & Chr(34) & DossierUnZip & Chr(34) & " " & "*.*"
     
        ShellAndWait ShellStr, vbHide
     
    End Sub
    Comme je ne le maitrise pas je n'arrive pas a degager le nom complet du fichier dézipper, et j'ai besoin de le connaitre car il peut etre differnt du nom du zip .

    Merci

  2. #2
    Membre éclairé
    Avatar de tamtam64
    Homme Profil pro
    stagiaire developpement vba
    Inscrit en
    Mai 2012
    Messages
    456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : stagiaire developpement vba
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2012
    Messages : 456
    Billets dans le blog
    17
    Par défaut de plus
    Je me permet de reposer la meme question dans ce code concernant la partie soulignée: c'est sensiblement identique , mais le e-aot ne signifie rien pour moi

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    
    Option Explicit
     
    Private Declare Function GetExitCodeProcess Lib "kernel32" _
        (ByVal hProcess As Long, lpExitCode As Long) As Long
     
    Private Declare Function OpenProcess Lib "kernel32" _
        (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) _
        As Long
     
    Private Declare Function CloseHandle Lib "kernel32" _
        (ByVal hObject As Long) As Long
     
    Private Const PROCESS_QUERY_INFORMATION = &H400
    Private Const STILL_ACTIVE = &H103
     
    Public UZipDownload As Boolean
     
    Private Sub ShellAndWait(ByVal PathName As String, Optional WindowState)
     
    Dim hProg As Long
    Dim hProcess As Long, ExitCode As Long
     
        UZipDownload = True
     
        If IsMissing(WindowState) Then WindowState = 1
     
        'hProg est un "process ID under Win32"
        hProg = Shell(PathName, WindowState)
     
        'To get the process handle:
        hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, hProg)
     
        Do
            'populate Exitcode variable
            GetExitCodeProcess hProcess, ExitCode
            DoEvents
        Loop While ExitCode = STILL_ACTIVE
     
     
        If ExitCode <> 0 Then 
            UZipDownload = False 
            Select Case ExitCode
                Case 1
                    MsgBox "Erreur 7z.exe code " & ExitCode & ": Warning (Non fatal error(s))"
                Case 2
                    MsgBox "Erreur 7z.exe code " & ExitCode & ": Fatal Error"
                Case 7
                    MsgBox "Erreur 7z.exe code " & ExitCode & ": Command line error"
                Case 8
                    MsgBox "Erreur 7z.exe code " & ExitCode & ": Not enough memory for operation"
                Case 255
                    MsgBox "Erreur 7z.exe code " & ExitCode & ": User stopped the process"
            End Select
        End If
     
     
        hProg = CloseHandle(hProcess)
    End Sub
     
    'With this example you unzip a fixed zip file: ZipLongName = "C:\Users\Ron\Test.zip"
    'Note this file must exist, this is the only thing that you must change before you test it
    'The zip file will be unzipped in a new folder in: Application.DefaultFilePath
    'Normal if you have not change it this will be your Documents folder
    'The name of the folder that the code create in this folder is the Date/Time
    'You can change this folder to this if you want to use a fixed folder:
    'DestinationPath = "C:\Users\Ron\TestFolder\"
    'Read the comments in the code about the commands/Switches in the ShellStr
     
    Sub UnzipFile_7z(ZipLongName As String, DestinationPath As String, ProgramName As String, ByVal ProgramPath As String)
     
    Dim ShellStr As String
     
        If Right(ProgramPath, 1) <> "\" Then ProgramPath = ProgramPath & "\"
     
        If Dir(ProgramPath & ProgramName) = "" Then
            MsgBox ProgramName & " not found in " & ProgramPath
            Exit Sub
        End If
     
        'extrait (e) toute (*.*)l'archive, renomme l'existant(-aot)
        ShellStr = ProgramPath & ProgramName & " e -aot" & " " & Chr(34) & ZipLongName & _
            Chr(34) & " -o" & Chr(34) & DestinationPath & Chr(34) & " " & "*.*"
     
        Call ShellAndWait(ShellStr, 1)
     
        If UZipDownload = False Then
            MsgBox "Unzip Failure"
        End If
     
    End Sub

  3. #3
    Expert confirmé
    Avatar de kiki29
    Homme Profil pro
    ex Observeur CGG / Analyste prog.
    Inscrit en
    Juin 2006
    Messages
    6 132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : ex Observeur CGG / Analyste prog.

    Informations forums :
    Inscription : Juin 2006
    Messages : 6 132
    Par défaut
    Salut, regarde ici

    -aot auto rename existing file (for example, name.txt will be renamed to name_1.txt).

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Je ne comprends pas l'intérêt de connaitre le nom du fichier avant de le deziper!
    Si tu créé un répertoire temporaire dans lequel tu dezip ton fichier un simple dir te donnera son nom
    rep=environ("userprofil") & "\temp" & Format(Now,"yyyy-mm-dd-hh-mm-ss")

  5. #5
    Membre éclairé
    Avatar de tamtam64
    Homme Profil pro
    stagiaire developpement vba
    Inscrit en
    Mai 2012
    Messages
    456
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : stagiaire developpement vba
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2012
    Messages : 456
    Billets dans le blog
    17
    Par défaut
    Bonjour,

    Merci pour vos reponses, ce n'est pas si évident, je veux dire quand on ne gere pas forcement les disks comme moi , mais si tu as un tuto sur ca je suis preneur, pour mieux comprendre.

    Moipersonnelement je prefererais avoir la main sur le nom du fichier qui est contenu, plutot que le chercher en realite

Discussions similaires

  1. Décompression de fichier ZIP avec 7zip en ligne de commande
    Par jam92400 dans le forum Scripts/Batch
    Réponses: 7
    Dernier message: 20/02/2019, 14h39
  2. Réponses: 8
    Dernier message: 14/11/2003, 22h51
  3. Dossier ou Fichier avec ShellListView
    Par MoussDiouf dans le forum Langage
    Réponses: 6
    Dernier message: 14/06/2003, 12h33
  4. [VB6] [Réseau] Récupérer la taille d'un fichier avec inet
    Par pcpunch dans le forum VB 6 et antérieur
    Réponses: 11
    Dernier message: 20/02/2003, 21h38
  5. enregistrer dans un fichier avec une appli mdi
    Par ferrari dans le forum C++Builder
    Réponses: 4
    Dernier message: 05/05/2002, 15h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo