Rename file when extracting using 7 zip command line

Viewed 8074

I'm using the following command to unzip a file:

"C:\Program Files\7-Zip\7z.exe" x "\\server\folder\backup.gz" -aoa "-o\\server\folder\"

I've been on the 7-zip help section and the examples for using -aoa aren't very clear. Using Google I can see solutions on a website called sevenzip, but it's not available. I also thought I could use the rn command but I wasn't sure where to place it.

2 Answers

I was searching for a solution myself. Of course, extracting a file to a completely different filename only makes sense if you're only extracting one file.

What I ended up doing was to extract to standard out (-so) and redirecting the output to the desired name:

  7z e my-compressed-file.7z -so readme.txt > new-filename.txt

Made some tweaks to Mark's scripts. For some more advanced use.

for %%f in (folder\*.7z) do (7z e "%%f" -so -r *filename1*.jpeg *filename2*.jpg > tmp\%%f.jpg)
  • now loops through multiple source files for %%f in (folder\*.7z)
  • wildcard for the source file with optional sub-folder folder\*.7z
  • multiple specific extracted files with wildcards *filename1*.jpeg *filename2*.jpg
  • searches inside the source file recursively -r
  • output file is named the same as input source file with optional sub-folder tmp\%%f.jpg
Related