Copy multiple files from different folder with same filename to one common folder using windows batch file

Viewed 1886

I have a Folder and some sub folders which contain a file with same file name but different values in it.I have to copy that files to a common folder but i want to keep all the files means i have to rename that files using batch file script in windows

Input Folder

D:\Data\Logs\Day1\DataLog.txt
D:\Data\Logs\Day2\DataLog.txt
D:\Data\Logs\Day3\DataLog.txt
D:\Data\Logs\Day4\DataLog.txt
D:\Data\Logs\Day5\DataLog.txt
D:\Data\Logs\Day6\DataLog.txt

Output Folder Like

D:\Data\Common\Logs\DataLog1.txt
D:\Data\Common\Logs\DataLog2.txt
D:\Data\Common\Logs\DataLog3.txt
D:\Data\Common\Logs\DataLog4.txt
D:\Data\Common\Logs\DataLog5.txt
D:\Data\Common\Logs\DataLog6.txt

i have tried this but its overwriting the existing file

pushd D:\Data\Logs
    for /r %%a in (*.*) do (
        COPY  "%%a" "D:\Data\Common\Logs\%%~nxa"
    )
popd
1 Answers
Related