I am not sure you can do what you are suggesting using the graphical user interface, but you can certainly from the command line:
FOR %i IN (*.*) DO 7z.exe a "%~ni.7z" "%i"
You would need to change directory (the cd
command) to the F:\Downloads
directory first, or 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 documents.
And the secret decoder ring:
%i
is a variable that holds the file name for each step in the loop
(*.*)
is the selection criteria, it could easily be *.exe or similar
7z.exe
is the command line version of 7-Zip
%~ni
- this expands the %i variable to just the file name - no extension
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:
FOR /F "usebackq delims=?" %i IN (`DIR /B /A:D`) DO 7z.exe a "%i.7z" "%i"
This works because of a few pieces of what seems like magic:
/F
tells FOR to iterate over the expanded value in ()
usebackq
tells FOR that I am going to pass a command and use the output to iterate
delims=?
tells FOR that I want to break tokens apart on the ?
- an illegal character in file names and directories. I only want one token.
- The
/B
in DIR
is for bare format - just the name
- The
/A:D
in DIR
is for restricting the results by attribute, the D is for directories
If you want to encapsulate this inside of a batch file, the only change you will need to make is to double escape the %i variable:
FOR %%i IN (*.*) DO 7z.exe a "%%~ni.7z" "%%i"
The approach would be the same, just the bit at the end would be a little different.
So for a particular file extension you would do this:
7z a -t7z archive.7z *.txt
You have just added all the .txt files.
But let's say you want to add a pdf and a doc to that, you would do this:
7z a -t7z archive.7z file.pdf file2.doc
Note: This won't create a new archive.7z, rather it will just add file.pdf and file2.doc to the archive.7z you created earlier.
Best Answer
I assume you want to use the zip format instead of the 7z format so set
-tzip
and include the path in quotes in case there is a space in the path.Check the cmd manual for more details: http://sevenzip.sourceforge.jp/chm/cmdline/commands/index.htm