bat批处理命令,批量压缩文件夹里的文件到压缩包并按文件数量以及当前日期重命名?

2024-11-21 21:21:48
推荐回答(1个)
回答(1):

不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件夹放一起运行
@echo off
rem 将多个文件夹分别压缩打包并以原文件夹名称、里面文件数量和当前日期组合成新名称命名
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
set "exefile=C:\Program Files\WinRAR\WinRAR.exe"
if not exist "%exefile%" (echo;"%exefile%" not found&pause&exit)
>"%tmp%\v.v" echo;d=date:WSH.echo right(Year(d),4) ^& right("0" ^& Month(d),2) ^& right("0" ^& Day(d),2)
for /f %%a in ('cscript -nologo -e:vbscript "%tmp%\v.v"') do set "today=%%a"
for /f "delims=" %%a in ('dir /ad/b') do (
set n=0&set "fd=%%a"&set "fn=%%~nxa"
for /f "delims=" %%b in ('dir /a-d/b/s "%%a\"') do set /a n+=1
setlocal enabledelayedexpansion
echo;"!fd!" --^> "!fn!(!n!个)%today%.rar"
endlocal
)
echo;%#% +%$%%$%/%@% %z%
pause
exit