[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程批处理在线视频分享
返回列表 发帖

[文件操作] 批处理如何修改压缩包内文件的文件名为压缩包的文件名?

如何批量修改压缩包内文件的文件名为压缩包的文件名???

比如有3个压缩文件文件,里面的文件名分别为a.mp4,b.avi,c.swf,压缩包的文件名为1.rar,2.rar,3.rar, 压缩包解压密码一致为123456,如何批量解压压缩包,同时将解压文件名替换成1.mp4,,2.avi,3.swf

回复 1# batbatbatbat

Win10 x64  WinRAR 5.6.1 环境,其它环境自行修改。
  1. @echo off & cd /d "%~dp0"
  2. rem 获取RAR安装位置
  3. reg query "HKLM\SOFTWARE\WinRAR" /v exe64>nul 2>nul && (
  4. for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\WinRAR" /v exe64') do set "R_Path=%%b"
  5. ) || for /f "tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\WOW6432Node\WinRAR" /v exe32') do set "R_Path=%%b"
  6. for /f "delims=" %%m in ("%R_Path%\..") do set "RarPath=%%~fm"
  7. REM 假定RAR密码为 123456
  8. md "%temp%\RARtmp" 2>nul
  9. for /f "delims=" %%a in ('dir/a-d/b "*.rar"') do (
  10. "%RarPath%\rar.exe" e ".\%%a" "%temp%\RARtmp\" -hp123456
  11. for /f "delims=" %%i in ('dir/a-d/b "%temp%\RARtmp\"') do "%RarPath%\rar.exe" rn ".\%%a" %%i "%%~na%%~xi"
  12. del /q/f "%temp%\RARtmp\*"
  13. )
  14. rd /s/q "%temp%\RARtmp"
  15. pause
复制代码
======================================

TOP

楼上来了个RAR,我就来个7ZIP
  1. @echo off
  2. rem 设置7ZIP路径
  3. set "path=%path%;C:\Program Files\7-Zip"
  4. rem 设置解压密码
  5. set "password=123456"
  6. for /r %%a in (*.rar,*.7z,*.zip) do (
  7. set "archpath=%%a"
  8. set "archname=%%~na"
  9. for /f "skip=18 tokens=6 delims= " %%b in ('7z l "%%a" *.* -p"%password%" -r^|find /v "files"') do (
  10. set "fullname=%%b"
  11. set "basename=%%~nb"
  12. call :get_name
  13. )
  14. )
  15. pause&exit
  16. :get_name
  17. call,set "newname=%%fullname:%basename%=%archname%%%"
  18. 7z rn "%archpath%" "%fullname%" "%newname%" -p"%password%">nul
  19. exit /b 0
复制代码
QQ 33892006

TOP

返回列表