code 1- @echo off
- rem 假设最多有20+1个重名文件
- for /f "delims=" %%i in ('dir /b /s /a-d *总结*.doc') do (
- if not exist "文件夹2\%%~nxi" (
- copy /y "%%i" "文件夹2\%%~nxi"
- ) else (
- set m=
- for /l %%l in (1,1,20) do (
- if not defined m (
- if not exist "文件夹2\%%~ni%%l%%~xi" (
- copy /y "%%i" "文件夹2\%%~ni%%l%%~xi"
- set m=1
- )
- )
- )
- )
- )
- pause
复制代码
code 2
- @echo off
- rem 文件名不含空格、特殊符号
- setlocal enabledelayedexpansion
- for /f "delims=" %%i in ('dir /b /s /a-d *总结*.doc') do (
- copy /y "%%i" "文件夹2\%%~ni!#%%~ni!%%~xi"
- set /a #%%~ni+=1
- )
- endlocal
- pause
复制代码
|