Created
September 19, 2020 06:52
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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