rzip7zip

7-Zip extracts file in encrypted zip but 7z.exe fails to see file


I have an archive file that I would like to decrypt and unzip and have the data inside available in R. After some trial and error, I ended up trying the system command in R and 7-zip to extract first before importing into R. However, the file extraction fails when using the 7z command line options. I have simplified everything below to highlight what appears to be an issue in the 7z request that I am using. I am hoping that someone can provide some guidance either to give a way of doing this within R or solve the command line issue with 7-Zip.

NOTE: What follows excludes R for now because the error seems to occur outside of R so it seemed best to isolate it to 7-Zip.

The .zip archive file in question can be extracted by right-clicking the file, choosing 7-Zip and then Extract Files. The system prompts for the password and extracts the file inside the zip archive afterwards without issue.

However, when attempting to use the 7-Zip command-line (7z) using either the e or x command, it says it is extracting the archive, sees the physical size is 3MB large, and then says "No files to process". The command line used was:

C:\Program Files\7-Zip>7z e "C:\TEST\EncryptedZip.zip" -p XXXXXXXXXX NOTE: File's actual password has been removed

If I try the x option, it gives the same response. When simply trying to list the files, it gives the following:

C:\Program Files\7-Zip>7z l "C:\TEST\EncryptedZip.zip" -p XXXXXXXXXX

7-Zip 23.01 (x64) : Copyright (c) 1999-2023 Igor Pavlov : 2023-06-20

Scanning the drive for archives:
1 file, 3474965 bytes (3394 KiB)

Listing archive: C:\TEST\EncryptedZip.zip

--
Path = C:\TEST\EncryptedZip.zip
Type = zip
Physical Size = 3474965

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
------------------- ----- ------------ ------------  ------------------------
                                     0            0  0 files 

So far, searching StackOverflow and other sites for a solution to the "No files to process" message indicate the issue is a syntax error in the command but I have simplified the command string and still don't see any.

What am I missing or how can I get more information about what is going on?


Solution

  • In R, to extract files compressed and encrypted with 7z I use the following. If you just want to list the files in the archive, change the first value of arg from "x" to "l".

    # This is a Windows path to 7z.exe,
    # also works if 7z is not on the PATH system variable
    cmd <- "C:/PROGRA~2/7-Zip/7z.exe"
    args <- c(
      "x",            # extract
      "filename",     # archive name
      "*",            # destination name
      "-pXXXXXXXXXX"  # password
    )
    system2(cmd, args)