Compressing Individual Files Into individual Archives Using 7Z Command Line
The following will allow you to compress all the individual files in a folder to each be inside their own archive / folder.
Prerequisites / Requirements
Set the environment PATH variable to include the 7-Zip folder path where the application is installed. e.g. C:\Program Files\7-Zip
FOR %i IN (*.*) DO 7z.exe a "%~ni.7z" "%i"
Explanation of each variable:
- %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
By default 7z will use it’s own file format, you can modify the command as follows to create zip (WinZIP / WIndows Compressed Folders) compatible files.
FOR %i IN (*.*) DO 7z.exe a -tzip "%~ni.zip" "%i"