本帖最后由 cutebe 于 2021-5-6 12:46 编辑
- ::复制所有(包含子目录中)的png到目标目录,重名则添加/修改数字后缀。
- @echo off
- setlocal enableDelayedExpansion
-
- set "sPath=D:\phpstudy_pro\WWW\xdzmb"
- set "tPath=D:\phpstudy_pro\WWW\fff"
-
- pushd %sPath%
- for /f "delims=" %%i in ('dir/s/b/a-d *.png')do (
- if exist "%tPath%\%%~nxi" (
- call :pngNum pngName "%%i"
- copy "%%i" "%tPath%\!pngName!%%~xi"
- )else copy "%%i" "%tPath%\"
- )
- popd
- goto :eof
- ::====完====
-
- :pngNum pngName pngPath
- setlocal
- pushd %~dp2
- set/am=1,@2=1
- for /l %%n in (0 1 9)do set _%%n=%%n
- set "strNum=%~n2"
- :numlp ::取末尾数字
- if defined _%strNum:~-1% (
- set/aLen+=1,m*=10
- set n=%strNum:~-1%%n%
- set strNum=%strNum:~,-1%
- goto :numlp
- )
- if "%Len%"=="" set/a num1=Len=1&goto :nend
- :nnext
- set/an1=1%n%+1
- set/ah=n1/m
- set num1=!@%h%!!n1:~-%Len%!
- if "%h%"==2 set/aLen+=1,m*=10
- :nend
- set "fName=%strNum%%num1%"
- if exist "%tPath%\%fName%%~x2" set n=%num1%&goto :nnext
- popd
- endlocal&set "%1=%fName%"
- goto :eof
复制代码
|