How To Use PowerShell and 7zip to create individual zip file for each .dmp file in a directory
Description
When you have a lot of files that you want to create individual zip archives of instead of one large zip archive you usually have to run 7zip on each one. This How To has the steps for using Windows PowerShell and the 7zip command line executable to make individual zip archives for all files of the same extension with one command from the command line. The example used here is for .dmp that are created by Windows Error Reporting, the files are usually large so zipping each one can save a lot of space.
How to Use PowerShell and 7zip to create individual zip file for each .dmp file in a directory
- Start up PowerShell from the Start menu
- Make sure to 'run as administrator'
- Move to the folder where your .dmp files are located
-
Use the following command line script to kick off the processing of the .dmp files
Copy<pre class="syntaxhighlighter-pre" xml:space="preserve">dir *.dmp | ForEach-Object { & "C:\Program Files\7-Zip\7z.exe" a -tzip ($_.Name+".zip") $_.Name }</pre>
The following is a break down of the commands
dir *.dmp
- selects all files in the directory
- use a different extension for different file types
|
- passes the results of the first command to the next
ForEach-Object
- loops thru all the elements from the first command
"C:\Program Files\7-Zip\7z.exe"
- The path on my PC for the 7z.exe command line executable
a
- The 7zip command to add to an archive
-tzip
- the 7zip command to create a zip archive
($_.Name+".zip")
- the 7zip command to name the archive created
- $_.Name
- the PowerShell command to get the full name of the file
- +".zip"
- adds the .zip extension to the archive created
- $_.Name
$_.Name
- the 7zip command for the file to archive
-
the PowerShell command to get the full name of the file
Article Number
2017221
Versions
All supported LPS family product versions
Environment
Any supported LPS family product environment