Page 1 of 1
Xcopy several times
Posted: 07 May 2013 07:10
by mor.bas
I want to copy some files in my batch file
how to do it more clearly then just
XCOPY "%~dp0External\Electronics" "%THIRD_FOLDER%\Electronics" /S /V /F /E /I /Y
And doing it X8 for 8 directories.
Thanks in advance....
Re: Xcopy several times
Posted: 07 May 2013 08:29
by abc0502
First SET All Your Directories ( from ) and ( to )in variables & SET the total number of the directories like this:
Code: Select all
SET "Max=3" // Max Directory Number
SET "DIR1=C:\Test 1" // source Dir number 1
SET "DIR2=D:\Test 2" // source Dir number 2
SET "DIR3=E:\Test 3" // source Dir number 3
SET "To1=C:\New Test 1" // Destination Dir number 1
SET "To2=D:\New Test 2" // Destination Dir number 2
SET "To3=E:\New Test 3" // Destination Dir number 3
Now using a for command to count from 1 till the max total number it will replace the numbers 1,2,3 etc in the last
DIR variable name and will pass it's value to one Xcopy command.
Code: Select all
For /L %%A In ( 1 1 %Max% ) Do (
echo !DIR%%A! : !To%%A!
)
Pause
Now this will display the Directories in your screen, replace echo command with:
Code: Select all
XCOPY "!DIR%%A!" "!To%%A!" /S /V /F /E /I /Y
Re: Xcopy several times
Posted: 07 May 2013 10:25
by Endoro
Nice
Code: Select all
@echo off &setlocal enabledelayedexpansion
for %%i in (
"C:\Test 1"="C:\New Test 1"
"D:\Test 2"="D:\New Test 2"
"E:\Test 3"="E:\New Test 3"
) do (
if defined source (echo XCOPY !source! %%i /S /V /F /E /I /Y
set "source=") else set "source=%%i")
Re: Xcopy several times
Posted: 07 May 2013 20:04
by Ocalabob
Greetings Endoro,
Sweet work!
I incorporated your script into my Robocopy batch file. The big plus
for me is that two months from now I'll be able to easily edit the batch
file. Thank you.
For consideration:
Code: Select all
::Source DOSTIPS.COM
::FOR IN DO Author Endoro
::Edited for use with Robocopy. Tested
::WIN 7. Local Date format = Ddd MM/DD/YYYY
@echo off &setlocal enabledelayedexpansion
Set fdate=%date:~12,2%_%date:~4,2%_%date:~7,2%
Set _Switches=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file information.
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity.
:: /MIR :: MIRror the Source directory tree.
Set _Options=/R:1 /W:1 /NP /NFL /NDL /LOG+:C:\%fdate%_Bak_log.txt^>nul
:: /R:n :: Number of Retries.
:: /W:n :: Wait time in seconds between retries.
:: /NP :: Turns off copy progress indicator (%) percentage copied.
:: /NFL :: No File Logging.
:: /NDL :: No Dir Logging.
:: /LOG+: :: Add to a log file named yy_mm_dd_Bak_log.txt. Create the
:: file if it does not exist.
Echo Robocopy in Progress...
for %%i in (
"C:\Mine"="E:\bak_files\Mine"
"C:\My_Programs"="E:\bak_files\My_Programs"
"C:\Utilities"="E:\bak_files\Utilities"
"C:\Pictures"="E:\bak_files\Pictures"
"C:\Bin"="E:\bak_files\Bin"
) do (
if defined source (Robocopy !source! %%i %_Switches% %_options%
set "source=") else set "source=%%i")
Echo.
Echo Robocopy Complete. Spacebar to Close this Window.
Pause>nul