How do I create seperate 7z files from each selected directory with 7zip command line?

Solution 1:

From the command prompt you could use something like:

FOR /D %i IN (d:\dir*.) DO 7z.exe a "e:\%~ni.7z" "%i"

In a batch file you'd need:

FOR /D %%i IN (d:\dir*.) DO 7z.exe a "e:\%%~ni.7z" "%%i"

BTW, you can get help on the FOR command by typing:

help for

at the command prompt.

Note that 7-zip has a separate command-line version called 7za.exe you would probably want to use instead of 7z.exe. It's in a separate .7z file download titled the "7-Zip Extra: standalone console version", which you can find at the 7-Zip download page. The archive contains multiple files, two of which are a small console za.exe file and a separate 7za.dll library file which the former uses to do the heavy-lifting — which are what you need.

Solution 2:

If you have tons of directories, using wildcard could reach some system limits.

With Cygwin or other Unix tools for Windows as UnxUtils, you could use the 'find'Unix command as follow:

cd <source directory>
find . -mindepth 1 -maxdepth 1 -type d -exec 7za a /<destination directory>/{}.7z {} \;

The '-mindepth'is important to avoid having the current directory returned by 'find'