那是根据好多年前自用的代码修改的,考虑的不是太周全,自用代码写得也不成熟,有点复杂,不是太好用,大致看了看,不知这样修改是否可行,如果不行的话,建议放弃此方案:- @echo off
- for /r "c:\1" %%a in ("*.doc") do (
- if not exist "E:\2\%%~nxa" (copy "%%a" "E:\2\") else (
- if not exist "E:\2\%%~na (2)%%~xa" (copy "%%a" "E:\2\%%~na (2)%%~xa") else (
- set n=2
- setlocal enabledelayedexpansion
- for /f "delims=" %%b in ('dir /b /a-d E:\2\*.doc^|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" "E:\2\%%~na (!n!)%%~xa"
- endlocal
- )
- )
- )
- pause
复制代码
|