我正在尝试编写一个批处理文件来查找所有zip,rar,tar.gz并将它们重新压缩为7zip自执行文件。我能够存储找到的文件并通过它们进行扫描,但我似乎无法将其压缩...或者do()中的所有内容都能正常工作。我还需要它来存储文本文件,以便我可以在它开始进程之前检查并删除任何不必要的文件
@echo off
::Scan for archives and store to file
dir /b /x *.* | find "rar" > rfound.txt
dir /b /x *.* | find "zip" > zfound.txt
dir /b /x *.* | find "tar.gz" > tfound.txt
echo Please check found files then hit enter
pause>nul
::Uncompress and recompress as 7z
for /f "tokens=1 delims=;" %%i in (rfound.txt) do ( 7za.exe e -y -otmp %%i * & pushd tmp & ..\7za.exe a -y -r -t7z ..\%%i * & popd & rmdir /s /q tmp )
for /f "tokens=1 delims=;" %%i in (zfound.txt) do ( 7za.exe e -y -otmp %%i * & pushd tmp & ..\7za.exe a -y -r -t7z ..\%%i * & popd & rmdir /s /q tmp )
for /f "tokens=1 delims=;" %%i in (tfound.txt) do ( 7za.exe e -y -otmp %%i * & pushd tmp & ..\7za.exe a -y -r -t7z ..\%%i * & popd & rmdir /s /q tmp )
pause
答案 0 :(得分:0)
测试:将变量设置为7-zip文件夹
引号允许您支持长文件名。
@echo off
::Scan for archives and store to file
dir /b /a-d *.rar *.zip *.tar.gz > found.txt
echo Please check found files then hit enter
pause>nul
set "7z=c:\program files\7-zip\7za.exe"
::Uncompress and recompress as 7z
for /f "delims=" %%a in (found.txt) do (
"%7z%" e -y -otmp "%%a"
pushd tmp
"%7z%" a -y -r -t7z "..\%%~na.7z" *
if errorlevel 1 echo an error occurred & pause
popd
rmdir /s /q tmp
)
答案 1 :(得分:0)
我最终通过使用extract / *选择所有文件来提取所有文件,然后压缩所有文件夹
@echo off
for /d %%a in (*) do (7za.exe a %%~na.exe -mmt -mx5 -sfx ".\%%a\*" & RD /s /q %%a)
pause
顺便说一下,我下载了7z cmd line standalone和自我提取库并将它们放在同一个文件夹中。
我在开发文件夹中节省了超过4GB的空间。 :)