| 1. |
Solve : Creating a bat file that will select Y when duplicate file exists? |
|
Answer» Hello All, 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 |
|