!BAT by 895866818 UESTC 2012-09-10 v1
setlocal
if "%debug%"=="" set debug=off
debug %debug%
::跳转帮助
if "%1"=="" goto :help
if /i "%1"=="-h" goto :help
if /i "%1"=="--help" goto :help
::开始
set path=%1
set tmp=%path:~-1%
if not "%tmp%"=="/" set path=%path%/
::图片计数
if "%2"=="" && ls %path% | call :pic
if not "%3"=="" && set /a picmax=%3 > nul && set /a picmin=%2 > nul
if "%3"=="" && if not "%2"=="" && set /a picmax=%2 > nul && set /a picmin=0 > nul
if %picmax% lss 0 && echo no file && exit
::计算随机序号
set /a hit=%@random% > nul
set /a hit=%picmax% - %picmin% +1 > nul
set /a hit=%@random% %% %hit% +%picmin% > nul
set pic=-1
::根据序号设定背景
ls %path% | call :setpic
exit
::计数
:pic
if "%1"=="" && set /a picmax=%pic% > nul && set /a picmin=0 && exit
set /a pic=%pic% + 1 > nul
shift
goto :pic
exit
::设定
:setpic
if "%1"=="" exit
set /a pic=%pic% + 1 > nul
if %pic%==%hit% && splashimage %path%%%1 > nul
if %pic%==%hit% exit
shift
goto :setpic
exit
::帮助
:help
debug on
echo 功能:随机设置背景图片
echo 命令格式: %~nx0 [路径]
echo 路径中应该包含要设定的背景图片[目前并不检测格式,一律认为可加载].
exit