Search code examples
vbagzip7zip

".gz" extraction problem via VBA Shell and 7z command line


I'm trying to create a function that returns unpacked file. It's only 1 file in archive. The problem comes with an unpacking part. I'm trying to get unpacked archive to the same folder as archive. Shell returns different not 0 values. The name seems not to be too long: Len( myFullPath ) = 101. The file name is - VZN_2022.csv.gz (packed file name)

I do not see a result of unpacking: there are no unpacked file in the folder. I use the code below:

Function Foo (ByVal myFullPath as String) as Boolean ' myFullPath = folder path + "\" + filename
    Call unpackeFile( CreateObject("Scripting.FileSystemObject").GetFile(myFullPath) )
End Function

Function unpackeFile(ByRef archive As Object) As Object
    ....
    commandStr = "C:\Program Files\7-Zip\7zFM.exe e " & archive.Path
    Call Shell(commandStr, 0)
    ....
End function

Debug.Print commandStr

C:\Program Files\7-Zip\7zFM.exe e \\av-fs01.av.local\profiles$\meltek\Desktop\VZN_2022.csv.gz

enter image description here


Solution

  • You need to wrap the path to the executable in quotation marks too, because it has a space in it - otherwise Shell will read up to the first space (i.e., C:\Program)and assume the rest are arguments:

    Function unpackeFile(ByRef archive As Object) As Object
        ....
        commandStr = Chr(34) & "C:\Program Files\7-Zip\7zFM.exe" & Chr(34) & " e " & Chr(34) & archive.Path & Chr(34) 
        Call Shell(commandStr, 0)
        ....
    End function