Skip to content

Instantly share code, notes, and snippets.

@mandeepsmagh
Created September 19, 2020 06:52
Show Gist options
  • Save mandeepsmagh/f4f0e003e0eebcedd8b1f8890dfd8403 to your computer and use it in GitHub Desktop.
Save mandeepsmagh/f4f0e003e0eebcedd8b1f8890dfd8403 to your computer and use it in GitHub Desktop.
Powershell script to loop over files to rename and create individual zip copies
# Get all XML files - xml can be replaced with any other file extension
$files = Get-ChildItem *.xml -Recurse
# Loop over files to rename and create individual zip copies
foreach ($file in $files) {
# Get file name without xml extension
$zipFileName = (Get-Item $file).BaseName
# Get dir name for each file and append file name without extension
$combinedPath = $file.DirectoryName+'\'+$zipFileName
# Create individual zip file for each xml
$compress = @{
Path = $file
CompressionLevel = "Fastest"
DestinationPath = $combinedPath+'.zip'
}
Compress-Archive @compress
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment