批处理,复制文件,如果有重名,则自动重命名

2024-11-15 18:47:22
推荐回答(2个)
回答1:

@echo off
setlocal enabledelayedexpansion
if not exist d:\123 md d:\123
pushd c:\123
for /f "tokens=*" %%i in ('dir/s/b') do (
if exist "d:\123\%%~nxi" (
for /f %%j in ('dir/b "d:\123\%%~ni*%%~xi"^|find /c /v ".*"') do set /a n=%%j + 1
copy "%%i" "d:\123\%%~ni!n!%%~xi") else copy "%%i" d:\123)

回答2:

顶一楼,非常专业!