Page 1 of 1

Batch file to move files based on a list Without overwriting Old file

Posted: 28 Jan 2017 13:34
by sidgaffar
Have a folder with files and a TXT file with a list of file names that I need copying from 1 folder to another

the script if copying the files but if the txt file has 2 files of the same name it keeps over writing the old file

In the list I have

file1.txt file2.txt file1.txt file2.txt

I want the achieve the following

file1.txt file2.txt file1(1).txt file2(1).txt

Code: Select all

@echo off
set Source=C:\Users\siddique.gaffar\Desktop\Artworks
set Target=C:\Users\siddique.gaffar\Desktop\Artworks Copy
set FileList=C:\Users\siddique.gaffar\Desktop\Artwork TXT File\Book1.txt
echo.

if not exist "%Source%" echo Source folder "%Source%" not found & goto Exit
if not exist "%FileList%" echo File list "%FileList%" not found & goto Exit
if not exist "%Target%" md "%Target%"

for /F "delims=" %%a in ('type "%FileList%"') do copy "%Source%\%%a" "%Target%"


:Exit
echo.
echo press the Space Bar to close this window.
pause > nul

Re: Batch file to move files based on a list Without overwriting Old file

Posted: 29 Jan 2017 06:53
by hckR360
see my answer on your stack overflow question.