简体   繁体   中英

Copy file type from sub directories, into one folder renaming files so they don't overwrite

I'd like to copy one filetype from sub directories, placing the copies into one folder, renaming them so they don't overwrite. Rename it but keep the file extension. I don't care what it is renamed to, as long as each copy has a unique name so they don't overwrite.

Here is my code now. It does everything I'd like except it overwrites files with same name:

Code:

set dSource=C:\Users\P Ditty\Documents\SH3\data\cfg\Careers
set dTarget=C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR
set fType=*.clg
for /f "delims=" %%f in ('dir /a-d /b /s "%dSource%\%fType%"') do (
copy  /v "%%f" "%dTarget%\" 2>nul
)

Thank you.

To avoid the duplicate problem by retaining original directory structure:

set dSource=C:\Users\P Ditty\Documents\SH3\data\cfg\Careers
set dTarget=C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR
set fType=*.clg

xcopy/s/i "%dSource%\%fType%" "%dTarget%"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM