Powershell: Alle Verzeichnisse in einem Quellverzeichnis in ein ZIP Archiv packen
Beschreibung: Immer wieder benötigt. Schnell und einfach viele Verzeichnisse in separate ZIP Archive packen. Da ist doch die Powershell wie geschaffen dafür. Also schnell die Variablen befüllt. Die Dateien ermitteln. Prüfen ob es ein Verzeichnis ist und dann mit 7Zip das ganze über cmd in ein Archiv packen. Fertig. Code:
1 2 3 4 5 6 7 8 9 10 11 12 |
[String] $strSource = "W:\Source" [String] $strDestination = "D:\Destination" [String] $strPath7Zip = "C:\Program Files\7-Zip" [String] $strFullCommand = "" $objFiles = Get-ChildItem -Path $strSource foreach ($objFile in $objFiles){ if ($objFile.Attributes -eq 'Directory'){ $strFullCommand = '"' + $strPath7Zip + '\7z.exe" a "' + $strDestination + '\' + $objFile.Name + '.7z" "' + $strSource + '\' + $objFile.Name + '"' cmd /c $strFullCommand } } |
Download: Klick für Download