- @echo off & title 批量处理
- color 0a & cd /d %~dp0
-
- ::::::::::可自定义设置区域::::::::::
-
- ::设置图片格式,无需添加*.jpg
- set PicExt=*.jpeg,*.png,*.bmp
-
- ::设置压缩包格式
- set ArchiveExt=*.rar,*.zip,*.7z
-
- ::设置压缩包解压密码,适用于有统一固定密码的压缩包,
- ::设置后针对无密码的压缩包会自动忽略,不影响解压。
- ::但针对不同密码的压缩包会出现解压失败的现象。
- ::此固定密码留空的话,每个有密码的压缩包都会提示密码输入
- set PassWord=
-
- ::设置WinRAR的安装路径
- set WinRarDir=%ProgramFiles%\WinRAR
-
- ::设置操作日志记录文件
- set Log=%~dp0操作日志记录.Log
-
-
- :::::::以下为主执行代码区域,请勿修改:::::::
-
- ::设定新的系统环境变量,勿动!!!
- set Path=%Path%;%WinRarDir%
-
-
- ::解压压缩包,并处理对应的文件夹
- echo, & echo 正在解压压缩包,并处理对应的文件夹,请等待 ...
- for %%a in (%ArchiveExt%) do (
- echo,
- call :Uncompressed "%%~a"
- call :Handle "%%~na"
- )
- echo, & echo 批量处理操作完成,请按任意键退出。
- pause >nul & exit
-
- :Uncompressed
- echo 解压 "%~1" 压缩包中 ...
- if defined PassWord (set UnPW=-p"%PassWord%") else set "UnPW="
- WinRAR x %UnPW% -ad -y "%~s1" * "%~sdp1" -ibck
- call :CreatLog "%errorlevel%" "%~1"
- goto :eof
-
- :CreatLog
- if %~1 equ 0 (
- del /f /q "%~2" >nul 2>nul && (
- echo %date:~,10% %time: =0% -- 解压成功 -- "%~2">>"%Log%"
- ) || (
- echo %date:~,10% %time: =0% -- 解压成功,但无法删除压缩包 -- "%~2">>"%Log%"
- )
- )
- if %~1 equ 1 echo %date:~,10% %time: =0% -- 发生非致命错误 -- "%~2">>"%Log%"
- if %~1 equ 2 echo %date:~,10% %time: =0% -- 发生一个致命错误 -- "%~2">>"%Log%"
- if %~1 equ 3 echo %date:~,10% %time: =0% -- 无效校验和,数据损坏 -- "%~2">>"%Log%"
- if %~1 equ 4 echo %date:~,10% %time: =0% -- 试图修改锁定的压缩文件 -- "%~2">>"%Log%"
- if %~1 equ 5 echo %date:~,10% %time: =0% -- 写入磁盘错误 -- "%~2">>"%Log%"
- if %~1 equ 6 echo %date:~,10% %time: =0% -- 文件打开错误 -- "%~2">>"%Log%"
- if %~1 equ 7 echo %date:~,10% %time: =0% -- 错误的命令行选项 -- "%~2">>"%Log%"
- if %~1 equ 8 echo %date:~,10% %time: =0% -- 内存不足 -- "%~2">>"%Log%"
- if %~1 equ 9 echo %date:~,10% %time: =0% -- 文件创建错误 -- "%~2">>"%Log%"
- if %~1 equ 10 echo %date:~,10% %time: =0% -- 没有找到与指定的掩码和选项匹配的文件 -- "%~2">>"%Log%"
- if %~1 equ 11 echo %date:~,10% %time: =0% -- 密码错误 -- "%~2">>"%Log%"
- if %~1 equ 255 echo %date:~,10% %time: =0% -- 用户中断操作 -- "%~2">>"%Log%"
- goto :eof
-
- :Handle
- echo 处理 "%~1" 文件夹中 ...
- pushd "%~1"
- for /r %%i in (*) do (
- if not "%%~dpi"=="%~dp1" (
- move "%%~i" >nul 2>nul && (
- echo %date:~,10% %time: =0% -- 文件已移动 -- "%%~i">>"%Log%"
- ) || (
- echo %date:~,10% %time: =0% -- 文件移动失败 -- "%%~i">>"%Log%"
- )
- )
- )
- for /r /d %%i in (*) do (
- dir /a-d/s/b "%%~i\*" >nul 2>nul
- if errorlevel 1 (
- rd /s/q "%%~i" >nul 2>nul && (
- echo %date:~,10% %time: =0% -- 空文件夹已被删除 -- "%%~i">>"%Log%"
- ) || (
- echo %date:~,10% %time: =0% -- 文件夹被占用,无法删除 -- "%%~i">>"%Log%"
- )
- ) else (
- echo %date:~,10% %time: =0% -- 不是空文件夹 -- "%%~i">>"%Log%"
- )
- )
-
- popd
- goto :eof
复制代码
|