标题: [文件操作] 批处理怎样递归查找所有png复制到一个文件夹内,同名的递增重命名 [打印本页]
作者: Edwin_ 时间: 2021-5-4 16:17 标题: 批处理怎样递归查找所有png复制到一个文件夹内,同名的递增重命名
- pushd D:\phpstudy_pro\WWW\xdzmb
- for /r %%a in (*.png) do (
- IF EXIST D:\phpstudy_pro\WWW\fff\%%~nxa (
- COPY %%a%%^(1) "D:\phpstudy_pro\WWW\fff"
- ) else (
- COPY %%a "D:\phpstudy_pro\WWW\fff"
- )
- )
- popd
- pause
复制代码
大概就是这个意思 这怎么改啊 在线等
作者: tz_being 时间: 2021-5-5 08:58
- @echo off &pushd D:\phpstudy_pro\WWW\xdzmb
- for /r %%i in (*.png) do (
- set "strName=%%~nxi" & set "n="
- call :CP "%%i"
- )
- pause & exit
-
- :CP
- if not exist "D:\phpstudy_pro\WWW\fff\%strName%" copy "%~1" "D:\phpstudy_pro\WWW\fff\%strName%" & goto :EOF
- if exist "D:\phpstudy_pro\WWW\fff\%strName%" set /a n+=1
- set "strName=%~n1(%n%)%~x1"
- goto :CP
复制代码
作者: cutebe 时间: 2021-5-6 12:30
本帖最后由 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
复制代码
作者: qixiaobin0715 时间: 2021-5-6 17:41
本帖最后由 qixiaobin0715 于 2021-5-8 17:05 编辑
利用以前写的代码进行修改,未经测试- @echo off
- set path1=D:\phpstudy_pro\WWW\xdzmb
- set path2=D:\phpstudy_pro\WWW\fff
- setlocal enabledelayedexpansion
- for /r %path1% %%a in (*.png) do (
- if not exist "%path2%\%%~nxa" (copy "%%a" "%path2%\") else (
- if not exist "%path2%\%%~na (2)%%~xa" (copy "%%a" "%path2%\%%~na (2)%%~xa") else (
- set n=2
- for /f "delims=" %%b in ('dir /b /a-d %path2%\*^|findstr /r /be /c:"%%~na ([0-9][0-9]*)%%~xa"') do (
- set "str=%%~nb"
- set "m=!str:%%~na (=!"
- set "m=!m:)=!"
- if !m! gtr !n! set /a n=m
- )
- set /a n+=1
- copy "%%a" "%path2%\%%~na (!n!)%%~xa"
- )
- )
- )
- pause
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |