- <#*,:&cls
- @echo off
- pushd "%~dp0"
- powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
- popd
- pause
- exit /b
- #>
- $dir2Compress = ".\*\*\*"
- Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop
- foreach ($item in (Resolve-Path -Path $dir2Compress -Relative)) {
- if (Test-Path -LiteralPath $item -PathType Container) {
- try {
- $zipfile = "$item.zip"
- Write-Host "$item -> $zipfile" -ForegroundColor Green
- Remove-Item -LiteralPath $zipfile -ErrorAction Ignore
- [System.IO.Compression.ZipFile]::CreateFromDirectory($item, $zipfile, "Optimal", $true, [System.Text.Encoding]::UTF8)
-
- } catch {
- $_ | Write-Host -ForegroundColor Red
- }
-
- }
- }
复制代码
|