gdraheim / zziplib

The ZZIPlib provides read access on ZIP-archives and unpacked data. It features an additional simplified API following the standard Posix API for file access
Other
62 stars 50 forks source link

Set output directory (destination directory) #105

Closed mb720 closed 3 years ago

mb720 commented 3 years ago

Hi and thanks a lot for zziplib!

Currently when I want to extract the contents of a zip file into a specific directory, I do this:

# unzzip -l prints leading whitespace, the file size, a space, and then the file name. We only want the file names
file_names=$(unzzip -l "my_archive.zip" | sed -e 's/^[[:space:]]*//' | cut -d' ' -f2-)
unzzip "my_archive.zip"
for file in $file_names; do
  mv "$file" "my_destination_directory"
done

I'm wondering if there's a more elegant (and maybe more robust) way to do this.

Thanks!

gdraheim commented 3 years ago

Well, the "unzzip" binary as well as the other ./bins are just examples. They do not support many options. The only optimization is using "-p" to pipe the extacted content directly into the target file.

Your specific example could however be done with a change-dir to the destination directory remembering the source zip location before the change-dir.

Btw, traditionally, getting the second arg is done with | awk '{print $2}'