我在一个文件夹中有多个文件 rom。我想将所有名称第一部分在下划线之前的文件压缩到 1 个 zip 文件中。例如:
rom_disk1.adf rom_disk2.adf in rom.zip
rom2_disk1.adf rom2_disk2.adf rom2_disk3.adf in rom2.zip
exc. exc.
答案1
哦,问题解开了。所以应该是这样的:
@echo off
if exist "%~1" (IF not exist "%~1\" exit) else (exit)
setLocal EnableDelayedExpansion
set Seven=C:\Program Files\7-Zip\7z.exe
set "Pasta=%~1"
If exist "%~dp0list.txt" del /q "%~dp0list.txt"
pushd "%Pasta%"
for /f "Delims=" %%a in ('dir /b *.*') do for /f "tokens=1* delims=_" %%b in ("%%~a") do call :Zipping "%%~a" "%%~b" "%%~c"
popd
pause
exit
:Zipping
for /f "delims=0123456789" %%a in ("%~3") do set P2Name=%%a
IF not Defined P1Name (
set P1Name=%~2
for /f "delims=" %%a in ('dir /b "*!P1Name!*!P2Name!*"') do >>"%~dp0list.txt" echo %%~dpnxa
"%Seven%" a -tzip -sdel -i@"%~dp0list.txt" "!P1Name!.zip" 1>nul 2>nul
IF exist "%~dp0list.txt" del /q "%~dp0list.txt"
)
IF /i not "%~2"=="!P1Name!" (
set P1Name=%~2
for /f "delims=" %%a in ('dir /b "*!P1Name!*!P2Name!*"') do >>"%~dp0list.txt" echo %%~dpnxa
"%Seven%" a -tzip -sdel -i@"%~dp0list.txt" "!P1Name!.zip" 1>nul 2>nul
IF exist "%~dp0list.txt" del /q "%~dp0list.txt"
)
goto :EOF
如果不起作用,请尝试这个:
@echo off
if exist "%~1" (IF not exist "%~1\" exit) else (exit)
setLocal EnableDelayedExpansion
set Seven=C:\Program Files\7-Zip\7z.exe
set "Pasta=%~1"
pushd "%Pasta%"
for /f "Delims=" %%a in ('dir /b *.*') do for /f "tokens=1* delims=_" %%b in ("%%~a") do (
IF not Defined P1Name (
set P1Name=%%b
"%Seven%" a -tzip -sdel "!P1Name!.zip" "!P1Name!*" 1>nul
)
IF /i not "%%b"=="!P1Name!" (
set P1Name=%%b
"%Seven%" a -tzip -sdel "!P1Name!.zip" "!P1Name!*" 1>nul
)
)