0% found this document useful (0 votes)
90 views

Archiving - How Do I Create Separate Zip Files For Each Selected File - Directory in 7zip - Super User

Como comprimir varias carpetas en archivos .7z individuales.

Uploaded by

deiwins
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Archiving - How Do I Create Separate Zip Files For Each Selected File - Directory in 7zip - Super User

Como comprimir varias carpetas en archivos .7z individuales.

Uploaded by

deiwins
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Search on Super User… Log in Sign up

Home
How do I create separate zip files for each selected file/directory in 7zip? Ask Question

Questions
Asked 8 years, 6 months ago Active 2 months ago Viewed 98k times
Tags

Users This is the internal zip packer from Total Commander:


Blog

Unanswered
31 This week, #StackOverflowKnows the
coronavirus’s long tail, sulfuric acid…

Is it time for a front-end framework?


13
Featured on Meta

Planned Maintenance scheduled for


Wednesday, February 5, 2020 for Data
Explorer

Ending my tenure as a superuser


However I want to use my 7zip packer. When I select 5 files, I get 5 separate .zip archives for
moderator
each selected file. How do I do that in 7zip?

zip archiving 7-zip total-commander packer Linked

By using our site, you this


acknowledge How would i make 7zip take a folder +
read and understand our Cookie Policy, Privacy Policy, and our Terms of 1Service.
share improve question that you have
edited Oct 11 '13 at 17:12 asked Jul 18 '11 at 14:16 subdirectories and individualy zip to bzip
Mxx Grumpy ol' Bear format each file in each sub directory
2,659 2 16 34 5,283 10 43 71

add a comment Related

5 Answers 4 Zip into separate files


active oldest votes
1 How do I create seperate 7z files from each
selected directory with 7zip command line?
I am not sure you can do what you are suggesting using the graphical user interface, but you 17 How to do “legacy” ZIP compression with
can certainly from the command line: 7zip?
54 2 How do I add files from a directory to a .zip-
FOR %i IN (*.*) DO 7z.exe a "%~ni.7z" "%i" File using the 7zip command line?

4 how to “preserve internal directory


You would need to change directory (the cd command) to the F:\Downloads directory first, or structure” when unzipping on windows?
whatever directory you would want to perform the mass compression. Also, it is easy enough to
substitute in *.exe or whatever extension you want to filter for to just compress those 0 All zip files downloaded as 7zip
documents.
0 Want new directory while extracting archive
And the secret decoder ring: file using 7zip

1 Modify .zip directory structure using 7zip


%i is a variable that holds the file name for each step in the loop
(prefferably) command line without
(*.*) is the selection criteria, it could easily be *.exe or similar decompressing

7z.exe is the command line version of 7-Zip 1 Recursively zip all files in a directory into
individual zip files… but in a separate
%~ni - this expands the %i variable to just the file name - no extension directory

If you wanted to just add the folders for a given directory, the command is a bit more complex
as by default FOR just works with files. We need to feed it some additional information: Hot Network Questions
Responding to planeswalker with doubling season
FOR /F "usebackq delims=?" %i IN (`DIR /B /A:D`) DO 7z.exe a "%i.7z" "%i" in play

This Nonogram seems a bit...... off


This works because of a few pieces of what seems like magic:
Repeat every other character in string starting with
second character
/F tells FOR to iterate over the expanded value in ()
148-to-141 conversion effect on spoke length?
usebackq tells FOR that I am going to pass a command and use the output to iterate
Can I be charged for murder if I throw peanuts at
delims=? tells FOR that I want to break tokens apart on the ? - an illegal character in file someone who has a severe peanut allergy and
names and directories. I only want one token. they die as a result of that?

The /B in DIR is for bare format - just the name begin tran instead of use db_name inside a SQL
Job for executing Stored Procedure
The /A:D in DIR is for restricting the results by attribute, the D is for directories
Capacitor Impedance ESR vs Frequency Curve
If you want to encapsulate this inside of a batch file, the only change you will need to make is to Find the Inverse Neighbor Pairs
double escape the %i variable:
My friend listed my name as a co-author on two
journal papers without my permission
FOR %%i IN (*.*) DO 7z.exe a "%%~ni.7z" "%%i"
pleTriwapt Sgpin (Triplet Swapping)

share improve this answer edited Jun 18 '14 at 22:53 answered Jul 18 '11 at 17:14 How to put a big equation in a single slide?

Goyuix Number of palindrome splits


6,011 3 31 47
Why would a 2019-nCoV protein sequence in the
NCBI database match a protein submitted in
Yea, except yours is 7z archive, I want a zip archive! So %~ni.zip instead? – Grumpy ol' Bear Jul 18 '11 2018?
at 17:38 What is "das Schulabschlusszeugnis" in this
context?
Better yet, I want zip or 7z with ultra compression. AND pack it in d:\packed. But so far your method
works! – Grumpy ol' Bear Jul 18 '11 at 17:43 When the road is blocked by animals, what's the
proper way to proceed?
1 Got it, thank you! FOR %i IN (.) DO 7z.exe a "i:\packed\%~ni.7z" "%i" -mx9 – Grumpy ol' Bear Jul 18
'11 at 18:01 Star Wars - Biggs Darklighter scene on Tattooine
in "A New Hope"
By the way, can you show me how to do that in a batch file? i.e. sperate-archive.bat – Grumpy ol' Bear Broken Coil Spring - How urgent is the repair?
Jul 18 '11 at 21:01
Exploration for a noble reason (something other
Thanks, and how do I add whole folders to that script, please? – Grumpy ol' Bear Jul 19 '11 at 12:52 than expansion of religion or conquest)?

show 2 more comments Now that I have iCloud, what benefit does Time
Machine provide?

Given fluids expand non-linearly how were


physicists able to make a linear temperature
I like Goyuix's answer. However, if you are using Windows 7 (or have Power Shell installed) and scale?
also use the command-line version of 7-zip, 7za.exe, then you can run this command:
Tax and social security for low income
16
dir | ForEach-Object { & "7za.exe" a $_.BaseName $_.Name } Power-Ending Patterns

How much ISO noise is removable in post?


You can also change "dir" to "dir *.exe" to only select executable files.
A question on a widely prevalent C naming
convention
One nice thing about Power Shell is that you are working with objects instead of strings. So you
could get really specific if you wanted to. For example:
Question feed

dir *.csv | ? { $_.Length -lt 18900 -and $_.LastWriteTime -ge [DateTime] "07/01/2011" }

This will only include files that:

1. have a csv extension


2. less than 18,900 bytes in size
3. last modified on or after 7/1/2011

EDIT If you want zip files instead of 7-zip files, use InfoZip's zip.exe instead.

share improve this answer edited Jul 18 '11 at 17:43 answered Jul 18 '11 at 17:33
jftuga
2,847 1 16 23

5 7-zip can also create zip files - have a look at the -t flag. Example: 7z a -tzip archive.zip *.exe –
Goyuix Jul 18 '11 at 22:48

Ok, $_.BaseName $_.Name works, but how do I do $_.BaseName $_.Name on another drive, in another
directory? Say f:\test\file1.7z etc. – Grumpy ol' Bear Jul 20 '11 at 9:06

add a comment

You can download and install 7zip plugin for Total Commander from
http://www.ghisler.com/plugins.htm Once you do that on the right side of the window from your
screenshot there will be another selection for 7zip compression. With that option you can
0
accomplish exactly what you are asking for.

share improve this answer answered Oct 11 '13 at 15:43


Mxx
2,659 2 16 34

add a comment

I've just been working on exactly this problem and one of the issues I found was duplication of
the folder name within the archive, i.e. when compressing a folder called "foo" an archive
containing .\foo\fighters.txt is produced instead of just one containing fighters.txt .
0
The answer, therefore is to go into the directory being processed and have the archive appear
in the previous (root) directory, then return to that directory in order to process the next folder.

It is also important to have 7ZIP ignore existing ZIP and CMD files within the root directory to
prevent them ending up within the archive, hence the -x!*.zip and -x!*.cmd exclusion
arguments.

This script will also maintain recursive folder structures.

@echo off

REM Ensures variables set within the batch file are local to
REM this script only and will be removed when finished.
setlocal

if exist *.zip goto zip_exist

for /d %%X in (*) do (


cls
cd /D %%X
"e:\Program Files\7-Zip\7z.exe" a -r -x!*.zip -x!*.cmd "..\%%X.zip" "*.*"
cd ..
)
goto end

:zip_exist
Echo.
Echo Note: for this script to work, compression of
Echo pre-existing zip files is not possible.

:end
pause

The above code should be copied to a batch file such as "compress_dirs.cmd" and run as
admin from the directory containing the folders you wish to compress.

Hope this helps.

share improve this answer edited Jun 23 '19 at 7:10 answered Jun 23 '19 at 5:57
Pi Hard
51 1 3

add a comment

If you need to keep the folder structure, and save each file in its own structure, try this:

Save this command in a file with extension .bat and put it in the folder you need to zip:
0
FOR /R %%i IN (*.*) DO "C:\Program Files\7-Zip\7z.exe" a "%%i.7z" "%%i" -sdel

Note:

-sdel: Deletes the original file (optional, if you only want to keep the compressed file)

share improve this answer answered Dec 5 '19 at 18:03


live-love
121 3

add a comment

Highly active question. Earn 10 reputation in order to answer this question. The reputation requirement
helps protect this question from spam and non-answer activity.

Not the answer you're looking for? Browse other questions tagged zip archiving 7-zip

total-commander packer or ask your own question.

SUPER USER COMPANY STACK EXCHANGE Blog Facebook Twitter LinkedIn


NETWORK
Tour Stack Overflow
Technology
Help Stack Overflow Business
Life / Arts
Chat Developer Jobs
Culture / Recreation
Contact About
Science
Feedback Press
Other
Mobile Legal site design / logo © 2020 Stack Exchange Inc; user contributions
licensed under cc by-sa 4.0 with attribution required.
Disable Responsiveness Privacy Policy rev 2020.2.3.35946

You might also like