[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. <#*,:&cls
  2. @echo off
  3. pushd "%~dp0"
  4. powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
  5. popd
  6. pause
  7. exit /b
  8. #>
  9. $dir2Compress = ".\*\*\*"
  10. Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop
  11. foreach ($item in (Resolve-Path -Path $dir2Compress -Relative)) {
  12.   if (Test-Path -LiteralPath $item -PathType Container) {
  13.     try {
  14.       $zipfile = "$item.zip"
  15.       Write-Host "$item -> $zipfile" -ForegroundColor Green
  16.       Remove-Item -LiteralPath $zipfile -ErrorAction Ignore
  17.       [System.IO.Compression.ZipFile]::CreateFromDirectory($item, $zipfile, "Optimal", $true, [System.Text.Encoding]::UTF8)
  18.       
  19.     } catch {
  20.       $_ | Write-Host -ForegroundColor Red
  21.     }
  22.    
  23.   }
  24. }
复制代码
微信:flashercs
QQ:49908356

TOP

本帖最后由 flashercs 于 2021-1-23 15:13 编辑
  1. <#*,:&cls
  2. @echo off
  3. pushd "%~dp0"
  4. powershell -NoProfile -ExecutionPolicy RemoteSigned -Command ". ([ScriptBlock]::Create((Get-Content -LiteralPath \"%~0\" -ReadCount 0 | Out-String ))) "
  5. popd
  6. pause
  7. exit /b
  8. #>
  9. $dir2Compress = ".\*\*\*"
  10. $rarexe="C:\Program Files\WinRAR\rar.exe"
  11. foreach ($item in (Resolve-Path -Path $dir2Compress -Relative)) {
  12.   if (Test-Path -LiteralPath $item -PathType Container) {
  13.     try {
  14.       $zipfile = "$item.rar"
  15.       Write-Host "$item -> $zipfile" -ForegroundColor Green
  16.       Remove-Item -LiteralPath $zipfile -ErrorAction Ignore
  17.       & $rarexe a $zipfile $item | Out-Null
  18.     } catch {
  19.       $_ | Write-Host -ForegroundColor Red
  20.     }
  21.   }
  22. }
复制代码
改成用WinRar,改下winrar安装路径
微信:flashercs
QQ:49908356

TOP

返回列表