bat 批量压缩 及解压缩

bat 批量压缩 及解压缩


代码:

@echo off
title 批量[压缩][解压缩]
for /f "tokens=2*" %%i in ('REG QUERY "HKLM\SOFTWARE\7-Zip" ^| find /i "Path"') do set "SevenZipPath=%%j"
SET PATH=%PATH%;%SevenZipPath%
cls

:menu
set yn=Q
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo  7z.exe 目录 %SevenZipPath%
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo  当前遍历目录: %~dp0 
echo 【Z】批量压缩子目录
echo 【U】批量解压缩文件
echo 【Q】退出
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
set /P yn=请选择:
if /i %yn%==Z goto goZ
if /i %yn%==U goto goU
if /i %yn%==Q goto goEnd
echo.&echo 任意键退出&pause>nul
exit

:goZ
set /p pass=密码:
if defined pass (
    for /f "delims=," %%i in ('dir /ad /b') do (
        echo 压缩目录: %%i  解压密码: %pass%
        7z a -t7z -mhe -p%pass% %%i.7z .\%%i\* >nul
    )
) else (
    for /f "delims=," %%i in ('dir /ad /b') do (
        echo 压缩目录: %%i
        7z a -t7z %%i.7z .\%%i\* >nul
    )
)
goto menu

:goU
set /p pass=密码:
for %%i in (*.7z,*.zip,*.rar) do (
    echo 解压: %%i   密码: %pass%
    7z x .\"%%i" -p%pass% -o".\%%~ni" -r -y -aos > nul
)
goto menu

:goEnd
exit

你可能感兴趣的:(批处理)