1.

Solve : Creating a bat file that will select Y when duplicate file exists?

Answer»

Hello All,

I am quite new to these boards and I need a little help with CREATING or if there is a possibility in creating a bat file for this long list files I have to copy from one our vms servers to a windows based SERVER.

I have created all the copy commands for each server and their respective file names, however this is a batch job that runs daily and only the date and time are different each day. The file names stay the same.

My problem.

If I were to copy a list of the files to copy at once. Windows would prompt me if I wanted to replace the current file. Thusly wiping out the other 3 copies behind it. So I am forced to copy each file individually and selecting Y for each new copy of the file.

My Question...

Can a bat file be created to automatically select the Windows options so that multiple files can be copied at one time INSTEAD of the single way I am doing now.

Here is an example of the files I am talking about. This might give you all a better idea of what I am trying to accomplish.


COPYING Process to the NN, NO and NP TGTs

NN's

copy \\opx1ua\symmap\news\src\cemp-n2000expansion.zip \\TGT1NNA\tgticker\
copy \\opx1ua\symmap\news\src\cemp-n2000expansion.zip \\TGT1NNB\tgticker\
copy \\opx1ua\symmap\news\src\cemp-n2000expansion.zip \\TGT2NNC\tgticker\
copy \\opx1ua\symmap\news\src\cemp-n2000expansion.zip \\TGT2NND\tgticker\

copy \\opx1ua\symmap\news\src\cemp-ric2n2000.zip \\TGT1NNA\tgticker\
copy \\opx1ua\symmap\news\src\cemp-ric2n2000.zip \\TGT1NNB\tgticker\
copy \\opx1ua\symmap\news\src\cemp-ric2n2000.zip \\TGT2NNC\tgticker\
copy \\opx1ua\symmap\news\src\cemp-ric2n2000.zip \\TGT2NND\tgticker\

copy \\opx1ua\symmap\news\src\cemp-xch2ric.zip \\TGT1NNA\tgticker\
copy \\opx1ua\symmap\news\src\cemp-xch2ric.zip \\TGT1NNB\tgticker\
copy \\opx1ua\symmap\news\src\cemp-xch2ric.zip \\TGT2NNC\tgticker\
copy \\opx1ua\symmap\news\src\cemp-xch2ric.zip \\TGT2NND\tgticker\



As you can see its quite a list and this is only a 1/4 of it . I am just trying to find a way to save me time each day instead of having to plug in each one of these individually.

Any help is sincerely appreciated!!

Regards,

James
St. Louis MO Welcome to the forums.

Quote from: GeddyLee

If I were to copy a list of the files to copy at once. Windows would prompt me if I wanted to replace the current file. Thusly wiping out the other 3 copies behind it. So I am forced to copy each file individually and selecting Y for each new copy of the file.

I'm not quite sure what the bold/underlined sentence means. However if you simply want to stop Windows prompting you for overwrite the simplest way would be to set the environment variable COPYCMD to /Y (SET COPYCMD=/Y). See here.

Other possibilities - use XCOPY with the /Y parameter or pipe Y to every Copy command such as (in a batch file) ECHO Y | COPY etc...

RSVPBelow is a batch script which will (should) copy 3 source files to four destinations based on the information you supplied..

It is assumed that (a) commands used in XP are available in your OS (b) ALL files to be copied are in the same path (c) the four destinations are static (d) not all files in the source folder are to be copied and (e) there is no requirement for error detection and reporting..

Note that output from the Copy program is suppressed.

If you want to copy more than 3 source files you must add a new line in the ":COMMENCE" section showing the new new source file name and increment the "%loop% equ" test (currently 4) by 1 for each file added in the "Exit after copying" section.

So, to copy a 4th file the new line in ":COMMENCE" would be:
if %loop% equ 4 set sourcefile=filename.ext && goto COPYFILES

and the %loop% equ" test would increment by 1 to 5.

The coding has NOT been tested
=======================

Good luck.

Code: [Select]

@echo off
cls

set loop=
set sourcefile=
set copycmd=/y


:: ..........Set path to source files......................

set sourcepath=\\opx1ua\symmap\news\src\cemp-

:: ..........Set destination file paths....................

set dest1=\\TGT1NNA\tgticker\
set dest2=\\TGT1NNB\tgticker\
set dest3=\\TGT2NNC\tgticker\
set dest4=\\TGT2NND\tgticker\

:: ...........Branch to set source filename................

goto COMMENCE

:: ...........Copy source files to destinations............

:COPYFILES
copy %sourcepath%%sourcefile% %dest1% > nul
copy %sourcepath%%sourcefile% %dest2% > nul
copy %sourcepath%%sourcefile% %dest3% > nul
copy %sourcepath%%sourcefile% %dest4% > nul

:: ............Set file to be copied.......................

:COMMENCE
set/a loop=%loop%+1

if %loop% equ 1 set sourcefile=n2000expansion.zip && goto COPYFILES
if %loop% equ 2 set sourcefile=ric2n2000.zip && goto COPYFILES
if %loop% equ 3 set sourcefile=xhc2ric.zip && goto COPYFILES

:: .............Exit after copying.........................

if %loop% equ 4 echo File copying complete
echo Press any key to continue
pause >nul




Discussion

No Comment Found