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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sidgaffar
Posts: 1
Joined: 28 Jan 2017 13:23

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

#1 Post by sidgaffar » 28 Jan 2017 13:34

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
Last edited by Squashman on 28 Jan 2017 17:17, edited 1 time in total.
Reason: MOD EDIT: Please use code tags. Removed extraneous comments.

hckR360
Posts: 5
Joined: 24 Dec 2016 20:48

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

#2 Post by hckR360 » 29 Jan 2017 06:53

see my answer on your stack overflow question.

Post Reply