|
本帖最后由 batche 于 2023-6-29 04:09 编辑
windows有自带的makecab压缩命令,但压缩文件夹要有list列表文件,我写了个脚本指定文件夹可以自动生成列表文件并压缩:
- @echo off
- set "d=123"
- setlocal enabledelayedexpansion
- cd /d "%~dp0"
- >>"%~dp0L.list" echo .set DestinationDir=%d%
- for /f "delims=" %%i in ('dir /b /a-d "%d%" 2^>nul') do >>"%~dp0L.list" echo "%d%\%%~nxi"
- for /f "delims=" %%d in ('dir /b /s /ad "%d%" 2^>nul') do (
- set "str=%%d"
- set "str=!str:%~dp0=!"
- >>"%~dp0L.list" echo .set DestinationDir=!str!
- for /f "delims=" %%f in ('dir /b /a-d "%%d" 2^>nul') do >>"%~dp0L.list" echo "!str!\%%~nxf"
- )
- makecab /f L.list /d CabinetNameTemplate="..\%d%.cab"
- rd /s /q disk1
- del /a /f /q setup.inf;setup.rpt;L.list
- endlocal
- pause
复制代码
除了用makecab,windows的explorer shell还自带zipped,也就是右键发送到中的zipped,explorer shell可以压缩和解压zip压缩包,单个文件夹还好,多个文件夹就要自动化操作了,命令行的方式批量压缩文件夹:
- '&(for /f "delims=" %%i in ('dir /b /ad') do cscript //nologo //e:vbscript "%~f0" "%%~fi.zip" "%%~fi")&pause&exit
- Set objShell = CreateObject("Shell.Application")
- Set objFSO = CreateObject("Scripting.FileSystemObject")
- objFSO.CreateTextFile(WScript.Arguments(0)).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
- objFSO.GetFile(WScript.Arguments(0)).Attributes = objFSO.GetFile(WScript.Arguments(0)).Attributes + 32
- objShell.Namespace(WScript.Arguments(0)).CopyHere objShell.Namespace(WScript.Arguments(1))
- '异步操作,需要等待
- WScript.Sleep 1000
复制代码 补充一下来源:blog.csdn.net/D_R_L_T/article/details/100584748
- powershell -c "Add-Type -A System.IO.Compression.FileSystem;dir -literal '%~dp0'|?{$_ -is [System.IO.DirectoryInfo]}|%%{[System.IO.Compression.ZipFile]::CreateFromDirectory($_.FullName, $_.FullName + '.zip')}"
- pause&exit
复制代码
|
|