How to Extract Individual Files from a Zip Using Tar, Info-Zip, or 7z?

  7zip, info-zip, tar, windows, zip

The file is "Target.zip". The top-level folder inside the zip is "Target". The desired file, "Renewal.xlsm", is at a deeper level. The directory tree in the zip should be duplicated for the uncompressed file.

I cannot use Scripting.FileSystemObject (scrrun.dll), Windows Script Host (wshom.ocx), or Microsoft Shell Controls (shell32.dll). Those aren’t good for my need, because they are asynchronous. Therefor, most similar questions on SO won’t help, and are not duplicates. I haven’t found my answer in those threads.

The following doesn’t work:

Tar

>tar -zxvf Target.zip "TargetNMD21-2022Renewal.xlsm"
tar: Error opening archive: Failed to open 'Target.zip'

https://www.tecmint.com/18-tar-command-examples-in-linux/

7z

>7z e -i!%"TargetNMD21-2022Renewal.xlsm"% Target.zip -o*
7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
Scanning the drive for archives:
1 file, 5896214 bytes (5759 KiB)
Extracting archive: Target.zip
Path = Target.zip
Type = zip
Physical Size = 5896214
No files to process
Everything is Ok
Files: 0
Size:       0
Compressed: 5896214

info-zip

This extracts the file, but i don’t get the directory-tree on the output.

>unzip -j "Target.zip" "TargetNMD21-2022Renewal.xlsm" -d "Target"

https://unix.stackexchange.com/a/57522/20731

Update: -j junks paths. The following works as desired, so i have a usable solution.

>unzip "Target.zip" "TargetNMD21-2022Renewal.xlsm" -d "Target"

https://unix.stackexchange.com/a/57522/20731

Would be cool to get solutions for 7z and tar.

Source: Windows Questions

LEAVE A COMMENT