批量复制所有文件而不覆盖 [英] Batch copying all files without overwriting
本文介绍了批量复制所有文件而不覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
set dSource=C:GamesSteamsteamapps
set dTarget=E:Demos
set fType=*.dem
xcopy/i "%dSource%\%fType%" "%dTarget%"
这是我目前必须复制所有文件的内容,但我怎样才能让它复制所有文件并重命名任何具有相同名称的文件,以便将两个副本都保存在目标文件夹中.
This is what I currently have to copy all my files, but how can I get it to copy all the files and rename any that have the same name, so that both copies are kept in the destination folder.
例如:
来源:demo.dem
目的地:demo.dem
Eg:
source:demo.dem
destination:demo.dem
前往:
目的地:demo.dem, demo(1).dem
Goes to:
destination:demo.dem, demo(1).dem
推荐答案
用 copy
试试这个解决方案:
Try this solution with copy
:
@echo off &setlocal
set "dSource=C:GamesSteamsteamapps"
set "dTarget=E:Demos"
set "fType=*.dem"
for %%i in ("%dSource%\%fType%") do if not exist "%dtarget%\%%~nxi" (copy /b "%%~i" "%dtarget%") else call :process "%%~i"
goto :eof
:process
set /a cnt=-1
:loop
set /a cnt+=1
set "fname=%dtarget%\%~n1(%cnt%)%~x1"
if exist "%fname%" goto :loop
copy /b "%~1" "%fname%"
goto :eof
endlocal
这篇关于批量复制所有文件而不覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文