自己以前处理文件写的代码,与你的需求还是有较大的差异,修改后未经验证。运行代码如果没问题,以后使用时可将所有copy改为move就行了。- @echo off
- setlocal enabledelayedexpansion
- 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
- 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"
- )
- )
- )
- pause
复制代码
|