批量复制所有文件而不会覆盖 [英] Batch copying all files without overwriting
本文介绍了批量复制所有文件而不会覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
set dSource=C:\Games\Steam\steamapps
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.
例如:
source:demo.dem
目的地:demo.dem
Eg:
source:demo.dem
destination:demo.dem
转到:
destination: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:\Games\Steam\steamapps"
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屋!
查看全文