Copy files with a same filename within a folder structure
Posted: 06 May 2010 06:20
Hey folks!
I searched through the web but I could not find anything helping me.
I'm trying to write a batch file in order to copy JUST the files within a folder structure to another folder.
All the files within the given folder structure do have the same name, but I don't want the batch script to overwrite the file that has been copied into the destination directory so far, instead it should in a way rename the files, so that in the end I do not have only one file called "filename.dat" but all of the files out of the source directory called "filename01.dat", "filename02.dat"... or something similar...
This is what I have got so far:
I am able to get the single files within the folder structure, but I don't really know how to manage the overwriting problem. (The first file is copied and is then overwritten because of the next file which has the exact same filename)
Hope you can help me!
Greetings, hannes2424
I searched through the web but I could not find anything helping me.
I'm trying to write a batch file in order to copy JUST the files within a folder structure to another folder.
All the files within the given folder structure do have the same name, but I don't want the batch script to overwrite the file that has been copied into the destination directory so far, instead it should in a way rename the files, so that in the end I do not have only one file called "filename.dat" but all of the files out of the source directory called "filename01.dat", "filename02.dat"... or something similar...
This is what I have got so far:
Code: Select all
@echo off
Set "sourceDir=%CD%
:: copy files
For /F "Delims=" %%! in ('Dir "%sourceDir%\" /b /s /a-d 2^>nul') do (
@xcopy "%%!" "%sourceDir%\%z%" /i /y /h /f /c
)
pause
I am able to get the single files within the folder structure, but I don't really know how to manage the overwriting problem. (The first file is copied and is then overwritten because of the next file which has the exact same filename)
Hope you can help me!
Greetings, hannes2424