Batch file 批量将多个归档文件重新压缩到7z中

Batch file 批量将多个归档文件重新压缩到7z中,batch-file,batch-processing,7zip,Batch File,Batch Processing,7zip,我试图编写一个批处理文件来查找所有zip、rar、tar.gz,并将它们重新压缩为7zip自执行文件。我可以让它存储找到的文件并扫描它们,但我似乎无法让它压缩。。。或是做()中的每件事。我还需要它来存储文本文件,这样我就可以在它开始进程之前检查并删除任何不必要的文件 @echo off ::Scan for archives and store to file dir /b /x *.* | find "rar" > rfound.txt dir /b /x *.* | find

我试图编写一个批处理文件来查找所有zip、rar、tar.gz,并将它们重新压缩为7zip自执行文件。我可以让它存储找到的文件并扫描它们,但我似乎无法让它压缩。。。或是做()中的每件事。我还需要它来存储文本文件,这样我就可以在它开始进程之前检查并删除任何不必要的文件

@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

测试:将变量设置为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
)

最后,我通过使用extract/*选择all来提取所有文件,然后压缩所有文件夹

@echo off
for /d %%a in (*) do (7za.exe a %%~na.exe -mmt -mx5 -sfx ".\%%a\*" & RD /s /q %%a)
pause
顺便说一句,我下载了7z cmd行单机版和库进行自我解压缩,并将它们放在同一个文件夹中


我在开发文件夹中保存了超过4GB的空间。:)

脚本是否崩溃、挂起或完成?错误设置
@echo on
并在do步骤中添加
&pause
,以分割每个部分。