Batch Script - (Stop services, move log files to other directory, append date once move) - date

I'm a newbie in batch scripting. How can i add a currentdate on the filename once i move the files to other directory? Can you please check my code below? Thanks!
This is how it works:
-- I need to copy some files to other directory in order to kill the running processes which are (dsst)
-- once the dsst is not running, it should stop the GESWCPAServer and delete the copied files in c:temp
-- Next, copy the logfiles from C:\LOGFILES to C:\LOGFILES\Archive.
-- after the files has been copied. it will now start the services.
Thanks!
-------------------------------------------------------------------
#ECHO off
copy D:\fp_swenv\cg_fp\config\*.magik c:\temp
sc stop GESWCPAServer
:loop
echo checking for task list
tasklist /NH /FI "IMAGENAME eq dsst_writer_acp.exe" | find /I "dsst_writer_acp.exe"
rem tasklist /NH /FI "IMAGENAME eq textpad.exe" | find /I "textpad.exe"
if %ERRORLEVEL% == 0 goto sleeploop
goto finish_up
:sleeploop
echo Sleeping 10secs
sleep 10
goto loop
:finish_up
del c:\temp\*.magik
sc stop GESWDisptcher51
sc stop GESWCPAClient
sleep 10
set logpath1="C:\LOGFILES"
set arcpath1="C:\LOGFILES\Archive"
c:
cd %logpath1%
FORFILES /D -1 /M *.log /C "cmd /c move #path %arcpath1%"
cd /D %arcpath1%
sc start GESWCPAServer
sleep 10
echo checking for task list
tasklist /NH /FI "IMAGENAME eq dsst_writer_acp.exe" | find /I "dsst_writer_acp.exe"
rem tasklist /NH /FI "IMAGENAME eq textpad.exe" | find /I "textpad.exe"
if %ERRORLEVEL% == 1 goto sleeploop
sc start GESWDisptcher51
sc start GESWCPAClient
#ECHO ON
---------------------------------------------------------------------------

Please check if this works -
Replace your below code with my code.
set logpath1="C:\LOGFILES"
set arcpath1="C:\LOGFILES\Archive"
c:
cd %logpath1%
FORFILES /D -1 /M *.log /C "cmd /c move #path %arcpath1%"
My Code -
EDIT - Added the zip option as requested by OP in the comment.
#echo OFF
set logpath1=c:\Logfiles
set arcpath1=c:\Logfiles\archive
cd /d %logpath1%
for /f %%x in ('wmic os get localdatetime ^| findstr /b [0-9]') do set TS=%%x
set yyyy=%TS:~0,4%
set mm=%TS:~4,2%
set dd=%TS:~6,2%
set hh=%TS:~8,2%
set min=%TS:~10,2%
set timestamp=%dd%-%mm%-%yyyy%_%hh%-%min%
for /f %%i in ('dir /b *.log') do call :moveandrename "%%i"
goto :jump
:moveandrename
set filename=%~n1
set fileextn=%~x1
move /y %filename%%fileextn% %arcpath1%\%filename%-%timestamp%%fileextn% >nul 2>&1
goto :eof
:jump
cd %arcpath1%
C:\Program Files\WinZip\wzzip.exe -a Archive_%timestamp%.zip *.log
if not %errorlevel% EQU 0 echo.Zip operation failed on %timestamp% >>zipresult.txt & goto :eof
del *.log
:eof
Cheers, G

Related

Folder being used for another process on batch script

I have a issue with a backup script I wrote. The backup is pretty simple. It will copy a directory to a destination path, and then zip it. I have a few If clauses to, example, delete the oldest backup if there are 5 or more .zip from previous backups.
The problem I'm facing is: after the XCOPY command has finished running I then run a PowerShell script from my Batch to zip the backup, but I get this error:
This happens becaus the .bat file is running. I've checked.
The code for both the batch and power shell script follows:
BATCH:
echo "========================================="
echo "=====| Backuping DCT Light's Files |====="
echo "========================================="
SET dct-light_src=\\w102xnk172\c$\inetpub\wwwroot\DCT_NEW
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set dct_light_startting_date=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set dct_light_startting_time=%%a%%b)
SET starttime=%dct_light_startting_date%
CD C:\Users\william_silva4\Desktop\tools_backup\dct_light\
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A "N=0"
FOR /F %%f IN ('DIR /B /A:-D "*"') DO (SET /A "N=!N!+1")
IF %n% == 5 (
powershell.exe -noexit -file "C:\Users\william_silva4\Desktop\remove_oldest.ps1"
) ELSE (
IF EXIST C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_%starttime%\ (
MD C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_%starttime%\dctlight_backup
SET dct-light_dtn=C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_%starttime%\dctlight_backup
echo A folder for this backup already exists. Beggining overwrite...
) ELSE (
MD C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_%starttime%\dctlight_backup
SET dct-light_dtn=C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_%starttime%\dctlight_backup\
)
)
CD C:\Users\william_silva4\Desktop\backup_completo
XCOPY %dct-light_src% %dct-light_dtn% /w /e /y /EXCLUDE:C:\Users\william_silva4\Desktop\backup_completo\exclusion.txt
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set dct_light_finished_date=%%c-%%a-%%b)
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set dct_light_finished_time=%%a%%b)
SET startdate=%dct_light_finished_date%
SET starttime=%dct_light_startting_date%_%dct_light_startting_time%
SET finishedtime=%dct_light_finished_date%_%dct_light_finished_time%
CD C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_%startdate%\
echo.LOG of %starttime%'s Backup>LOG_%startdate%.txt
echo.Start time: %starttime%>>LOG_%startdate%.txt
echo.Finished time: %finishedtime%>>LOG_%startdate%.txt
CD C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_%startdate%\dctlight_backup\
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A "N=0"
FOR /F %%f IN ('DIR /S /B /A:-D "*"') DO (SET /A "N=!N!+1")
CD ../
echo.Files copied: %N%>>LOG_%startdate%.txt
powershell.exe -noexit -file "C:\Users\william_silva4\Desktop\zip_backups.ps1"
pause>nul
POWER SHELL:
#DCT Light's zipping
Start-Sleep -s 15
$source = "C:\Users\william_silva4\Desktop\tools_backup\dct_light"
$date = Get-Date -UFormat "%Y-%m-%d"
$destination = "C:\Users\william_silva4\Desktop\tools_backup\dct_light\dctlight_backup_$date.zip"
If(Test-path $destination) {Remove-item $destination}
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($source, $destination)
Remove-Item $source\* -Recurse -Exclude *.zip
What I have tried to solve the problem:
Create a Master.ps1 with a list of scripts to run, where the first one is, obliviously, the backup batch file and then the zipping ps1 file.
Call the zipping ps1 file from the backup batch file on another window and then kill the batch. In this case, the first line of the zipping script was:
Start-Sleep -s 15
So I was certain that the batch was killed before I really started zipping.
None of the above worked. Any help? If nothing works I'll just schedule them as separated tasks on Windows.

Windows script to delete everything but image file extensions

I want to create a script on Windows 7 to delete everything in a directory that is not a picture.
So
for all files in directory X
if file y does not have extension in (.png, .gif, .jpeg)
delete y
end
that's it
how can I find or create such a script
mind you, some pictures are important, so this script has to work correctly :) I don't think I should be experimenting here, and even if I tested my own script on a small directory with experimental files, I am not confident that I should try it.
I have this code as suggested:
::extensions are delimited with space // filename is del_stuff.bat
set "extensions_list=.png .gif .jpeg .bmp .jpg "
pushd "C:\Users\denman\Desktop\xxx\"
for /f "delims=" %%f in ('dir /b ^|findstr /i /e /v "%extensions_list%" ') do (
echo del /q /f "%%~f"
)
popd
But I get this error:
Using Powershell, you can get the list of files you need with something like this:
Get-ChildItem | where {!$_.PsIsContainer -and !(#(".png",".gif",".jpeg") -contains $_.Extension) }
I left the Delete command to you, make sure the list returns correct results before you do it.
#echo off
::extensions are delimited with space
set "extensions_list=.png .gif .jpeg "
pushd "C:\Directory_with_pictures" && (
for /f "delims=" %%f in ('dir /b /a-d ^|findstr /i /e /v "%extensions_list%" ') do (
echo del /q /f "%%~f"
)
popd
)
The 'echo' is to verify the result .remove the echo to activate deletion.And change "C:\Directory_with_pictures" with the actual path.
EDIT testing the script:
#echo off
md test_dir>nul 2>&1
echo #>test_dir\t1.png
echo #>test_dir\t1.txt
echo #>test_dir\t1.tst
echo #>test_dir\t1.jpg
echo #>test_dir\t1.gif
echo #>test_dir\t2.png
echo #>test_dir\t2.txt
echo #>test_dir\t2.tst
echo #>test_dir\t2.jpg
echo #>test_dir\t2.gif
echo -- before deleting--
dir /b .\test_dir\*
echo(
echo(
::extensions are delimited with space
set "extensions_list=.png .gif .jpeg .jpg"
pushd "test_dir"
for /f "delims=" %%f in ('dir /b ^|findstr /i /e /v "%extensions_list%" ') do (
del /q /f "%%~f"
)
popd
echo -- after deleting --
dir /b .\test_dir\*
Output:
-- before deleting--
t1.gif
t1.jpg
t1.png
t1.tst
t1.txt
t2.gif
t2.jpg
t2.png
t2.tst
t2.txt
-- after deleting --
t1.gif
t1.jpg
t1.png
t2.gif
t2.jpg
t2.png

batch file that opens cmd prompt types string as command line

I got my batch file to open cmd prompt and change directory successfully, however what I cannot get to work is after the directory has changed I want the batch to then to enter a string as a command.
I've tried cmd /k string but that didn't seem to work, the cmd just sits at the changed directory. I've also tried:
set Opvar= echo string
%Opvar%
Again it just sits at the last changed directory. The batchisp line that's commented out is what the string is that I want to act as if I typed the whole string and pressed enter at the current directory prompt.
Here's the whole thing:
#Echo OFF
FOR /F "Tokens=*" %%# IN ('Reg Query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" ^| FIND "-1000"') DO (
FOR /F "Tokens=2,*" %%A IN ('Reg Query "%%#" /v "ProfileImagePath" ^| FIND /V "%%#"') DO (
set drive=%%B
Echo Admin SID: %%~n#
Echo Admin Folder: %%B
)
)
:Ask
echo What are you flashing? Please select one option(1,2, or 3):
echo 1. Main Board w/ 6-Station OpCon.
echo 2. Main Board w/ 12-Station Opcon.
echo 3. OpCon Board.
set /P INPUT=Type input: %=%
If "%INPUT%"=="1" goto Option1
If "%INPUT%"=="2" goto Option2
If "%INPUT%"=="3" goto Option3
::::::::::::
:Option1
echo Starting 6-Station DFU flash...
echo xcopy "%~dp0M1k_MainPCB\6-STATION\*.*" "%drive%\Desktop\MainPCB6\" /d /s /h /v /c /f /k /y
echo cmd /k "cd /d %drive%\Desktop\MainPCB6\6-STATION\Debug\"
goto End
::::::::::::
:Option2
echo Starting 12-Station DFU flash...
echo xcopy "%~dp0M1k_MainPCB\12-STATION\*.*" "%drive%\Desktop\MainPCB12\" /d /s /h /v /c /f /k /y
echo cmd /k "cd /d %drive%\Desktop\MainPCB12\12-STATION\Debug\"
goto End
::::::::::::
:Option3
echo Starting OpCon DFU flash...
xcopy "%~dp0M1k_SWPCB\SWPCB\*.*" "%drive%\Desktop\SWPCB\" /d /s /h /v /c /f /k /y
cmd /k "cd /d %drive%\Desktop\SWPCB\SWPCB\Debug\"
::batchisp -device at32uc3a0512 -hardware usb -operation erase f memory flash blankcheck loadbuffer SWPCB.elf program verify start reset 0
goto End
::::::::::::
:End
echo ******
echo *****
echo ****
echo ***
echo **
echo *
echo Flash Completed! Press any key to exit...
Pause>NUL&Exit
Any help would be much appreciated.
Thank you
You are changing the working directory in a new instance of CMD (CMD /K), use PUSHD to change the working directory in your current CMD instance and POPD to return to the last used directory:
#Echo OFF
PUSHD %WINDIR%"
Echo I'm on "%CD%" Directory!
POPD
Echo I'm on "%CD%" Directory!
Pause&Exit
Change your code to this:
:Option3
echo Starting OpCon DFU flash...
xcopy "%~dp0M1k_SWPCB\SWPCB\*.*" "%drive%\Desktop\SWPCB\" /d /s /h /v /c /f /k /y
PUSHD "%drive%\Desktop\SWPCB\SWPCB\Debug"
batchisp -device at32uc3a0512 -hardware usb -operation erase f memory flash blankcheck loadbuffer SWPCB.elf program verify start reset 0
POPD
goto :End
...Or if you want to start directly the command in a new instance of CMD change it to this:
CMD /k "Start /W """" "%drive%\Desktop\SWPCB\SWPCB\Debug\batchisp" -device at32uc3a0512 -hardware usb -operation erase f memory flash blankcheck loadbuffer SWPCB.elf program verify start reset 0"
PS: Remember that you don't need to change the working dir to start an app, you can write the path followed by the process name like in my last example.

How to set variable with the result of findstr

I am trying to write a batch file which searches for pdf files and finds how many pages they have and loop all pages.
I wrote the following. I can find the files, I can even find the pagecounts with a tool named pdftk. The results is as below.
C:\Users\test\Documents\fishes\Fish_1.pdf
NumberOfPages: 5
How can I set a variable which has the value of 5?
#ECHO off
for /R %%i IN (*.pdf) DO (
ECHO %%i
"C:\Program Files (x86)\PDF Labs\PDFtk Server\bin\pdftk.exe" %%i dump_data | findstr NumberOfPages
set pagecount = findstr NumberOfPages ???
FOR /L %%j IN (1,1,%pagecount%) DO (
ECHO "page " + %%j
)
)
You were already 90% there. Use the FOR /F command to process the results of a command. Type HELP FOR from the command prompt for more info.
for /f "tokens=2" %%A in (
'"C:\Program Files (x86)\PDF Labs\PDFtk Server\bin\pdftk.exe" %%i dump_data ^| findstr NumberOfPages'
) do set numberOfPages=%%A

Batch file for copying files

I'm looking to do some massive copy's during a server migration and I need to better understand the copy commands in Windows Server. I've been toying with xcopy, but I really am having a difficult time understanding it fully. Is there some good literature out there or can anyone help me with this? Is there any other software or commands I could use?
I'm looking to do this to a full array of 37 servers, so I'm looking for guidance on creating a script I can input multiple directories into so that I can leave this running for as long as it takes.
So far this is what I've been doing:
xcopy C:\Directory\*.* \\Server\Directory\*.* /S /V
It's working, but when I get an error it stops... and I'm not really sure the direction I should go for starting up a batch file for this project. Should I use variables? Should I prompt for the directories? What's the "best" way?
Any help would be appreciated, thanks in advanced!
Now on to actually solving what you're asking.
I have run into a similar problem at my work as well. I've actually developed some code that can take 3 copies at a time (either roboCopy or xCopy) and will create the script for later use.
Try this out and let me know if it works!
#ECHO OFF
COLOR 0A
TITLE product_X Migration Copy Tool
echo.This script should always be run FROM the Source Machine
echo.
choice /C:RX /N /M "(R)RoboCopy or (X)Xcopy:"
IF '%ERRORLEVEL%'=='1' set copyMode=Robo
IF '%ERRORLEVEL%'=='2' set copyMode=X
cls
echo.Are you using UNC paths?
choice /C:YN /N /M "(Y)Yes or (N)No"
IF '%ERRORLEVEL%'=='1' set UNC=UNC
IF '%UNC%'=='UNC' GOTO regEdit
IF '%ERRORLEVEL%'=='2' set UNC=drive
IF '%UNC%'=='drive' GOTO SourceDrive1
:SourceDrive1
cls
IF /I '%source1Error%'=='T' echo.Location does not exist, try again...
IF /I '%source1Error%'=='T' echo.
set source1Error=F
echo._.-*Set your FIRST copy source/destination*-._
echo.
set SourceDrive1=
set /p SourceDrive1=What is the Local folder you want to copy from?:
IF NOT DEFINED SourceDrive1 set source1Error=T
IF /I '%source1Error%'=='T' GOTO SourceDrive1
echo.
:destDrive1
echo.
echo.What is the %UNC% location you want to copy %sourceDrive1% to?
set dest1Error=F
set destDrive1=
IF '%UNC%'=='UNC' echo.(Make sure you include the '\\' before your location)
set /p destDrive1=:
IF NOT DEFINED destDrive1 set dest1Error=T
IF /I '%dest1Error%'=='T' echo.Location does not exist, try again...
IF /I '%dest1Error%'=='T' GOTO destDrive1
cls
verify >nul
echo.You will perform a %copyMode%Copy on %SourceDrive1%\*.* to %destDrive1%\*.*
echo.
echo.Is this correct?
echo.(If you choose (Z)Done you will move on to start %copyMode%Copying)
echo.
choice /C:YNXZ /N /M "(Y)Yes, (N)No, (X)Back or (Z)Done:"
IF '%ERRORLEVEL%'=='1' GOTO SourceDrive2
IF '%ERRORLEVEL%'=='2' GOTO destDrive1
IF '%ERRORLEVEL%'=='3' GOTO SourceDrive1
IF '%ERRORLEVEL%'=='4' set allDone=1
IF '%ERRORLEVEL%'=='4' GOTO finalWarning
:SourceDrive2
cls
IF /I '%source2Error%'=='T' echo.Location does not exist, try again...
IF /I '%source2Error%'=='T' echo.
set source2Error=F
echo._.-*Set your SECOND copy source/destination*-._
echo.
set SourceDrive2=
set /p SourceDrive2=What is the next Local folder you want to copy from?:
IF NOT DEFINED SourceDrive2 set source2Error=T
IF /I '%source2Error%'=='T' GOTO SourceDrive2
echo.
:destDrive2
echo.
echo.What is the %UNC% location you want to copy %SourceDrive2% to?
set dest2Error=F
set destDrive2=
IF '%UNC%'=='UNC' echo.(Make sure you include the '\\' before your location)
set /p destDrive2=:
IF NOT DEFINED destDrive2 set dest2Error=T
IF /I '%dest2Error%'=='T' echo.Location does not exist, try again...
IF /I '%dest2Error%'=='T GOTO destDrive2
cls
verify >nul
echo.You will perform a %copyMode%Copy on %SourceDrive2%\*.* to %destDrive2%\*.*
echo.
echo.Is this correct?
echo.(If you choose (Z)Done you will move on to start %copyMode%Copying)
echo.
choice /C:YNXZ /N /M "(Y)Yes, (N)No, (X)Back or (Z)Done:"
IF '%ERRORLEVEL%'=='1' GOTO SourceDrive3
IF '%ERRORLEVEL%'=='2' GOTO destDrive2
IF '%ERRORLEVEL%'=='3' GOTO SourceDrive1
IF '%ERRORLEVEL%'=='4' set allDone=2
IF '%ERRORLEVEL%'=='4' GOTO finalWarning
:SourceDrive3
cls
IF /I '%source3Error%'=='T' echo.Location does not exist, try again...
IF /I '%source3Error%'=='T' echo.
set source3Error=F
echo._.-*Set your SECOND copy source/destination*-._
echo.
set SourceDrive3=
set /p SourceDrive3=What is the last Local folder you want to copy from?:
IF NOT DEFINED SourceDrive3 set source3Error=T
IF /I '%source3Error%'=='T' GOTO SourceDrive3
echo.
:destDrive3
echo.
echo.What is the %UNC% location you want to copy %SourceDrive3% to?
set dest3Error=F
set destDrive3=
IF '%UNC%'=='UNC' echo.(Make sure you include the '\\' before your location)
set /p destDrive3=:
IF NOT DEFINED destDrive3 set dest3Error=T
IF /I '%dest3Error%'=='T' echo.Location does not exist, try again...
IF /I '%dest3Error%'=='T' GOTO destDrive3
cls
verify >nul
echo.You will perform a %copyMode%Copy on %SourceDrive3%\*.* to %destDrive3%\*.*
echo.
echo.Is this correct?
choice /C:YNX /N /M "(Y)Yes, (N)No or (X)Back"
IF '%ERRORLEVEL%'=='1' GOTO finalWarning
IF '%ERRORLEVEL%'=='2' GOTO destDrive3
IF '%ERRORLEVEL%'=='3' GOTO SourceDrive2
:finalWarning
cls
echo.
echo. * * * WARNING * * *
echo.This will execute with the following variables
echo.
echo.%copyMode%Copy:
echo.%SourceDrive1%\*.* to %destDrive1%\*.*
echo.
IF '%allDone%'=='1' GOTO questionWarning
echo.%SourceDrive2%\*.* to %destDrive2%\*.*
echo.
IF '%allDone%'=='2' GOTO questionWarning
echo.%SourceDrive3%\*.* to %destDrive3%\*.*
echo.
:questionWarning
echo.Do you want to SAVE your config to use later?
echo.
echo.Select Yes to start, No to go to the beginning or Back to go back one step
choice /C:YNX /N /M "(Y)Yes, (N)No or (X)Back"
IF '%ERRORLEVEL%'=='1' set copyConfig=Y
IF '%ERRORLEVEL%'=='2' set copyConfig=N
IF '%ERRORLEVEL%'=='3' GOTO SourceDrive3
cls
IF /I '%copyConfig%'=='Y' goto saveConfig
IF /I '%copyConfig%'=='N' goto SourceDrive1
:preStart
FOR /F %%A IN ('TIME/T') DO SET time=%%A
FOR /F "tokens=1-4 delims=/ " %%B IN ('DATE /t') DO SET date=%%C/%%D/%%E
echo.
echo.Do you want to start %copyMode%Copying?
echo.Select Yes to start, No to go to the beginning or Back to go back one step
choice /C:YNX /N /M "(Y)Yes, (N)No or (X)Back"
IF '%ERRORLEVEL%'=='1' GOTO start
IF '%ERRORLEVEL%'=='2' GOTO SourceDrive1
IF '%ERRORLEVEL%'=='3' GOTO questionWarning
:start
IF NOT EXIST C:\TEMP\product_X\TEMP MD C:\TEMP\product_X\TEMP
echo.%date% -%time% - %copyMode%Copy Started>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
cls
echo.Running...
IF /I '%copyConfig%'=='Y' explorer.exe C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\
IF /I '%copyMode%'=='robo' goto roboCopy
IF /I '%copyMode%'=='X' goto xCopy
:xCopy
REM xcopy Source Destination /TRIGGERS
IF NOT EXIST %destDrive1% MD %destDrive1%
echo.%date% -%time% - %SourceDrive1%\*.* - to - %destDrive1%\*.*>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
xcopy %SourceDrive1%\*.* %destDrive1%\*.* /d /e /c /r /y
IF '%allDone%'=='1' GOTO end
IF NOT EXIST %destDrive2% MD %destDrive2%
echo.%date% -%time% - %SourceDrive2%\*.* - to - %destDrive2%\*.*>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
xcopy %SourceDrive2%\*.* %destDrive2%\*.* /d /e /c /r /y
IF '%allDone%'=='2' GOTO end
IF NOT EXIST %destDrive3% MD %destDrive3%
echo.%date% -%time% - %SourceDrive3%\*.* - to - %destDrive3%\*.*>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
xcopy %SourceDrive3%\*.* %destDrive3%\*.* /d /e /c /r /y
:roboCopy
IF NOT EXIST %destDrive1% MD %destDrive1%
IF NOT EXIST %destDrive1%\RoboCopy_Logfile MD %destDrive1%\RoboCopy_Logfile
echo.%date% -%time% - %SourceDrive1%\*.* - to - %destDrive1%\*.*>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
robocopy %SourceDrive1%\*.* %destDrive1%\*.* /R:5 /W:3 /Z /XX /TEE /LOG+:%destDrive1%\RoboCopy_Logfile\%destDrive1%_Log.txt
IF '%allDone%'=='1' GOTO end
IF NOT EXIST %destDrive2% MD %destDrive2%
IF NOT EXIST %destDrive2%\RoboCopy_Logfile MD %destDrive2%\RoboCopy_Logfile
echo.%date% -%time% - %SourceDrive2%\*.* - to - %destDrive2%\*.*>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
robocopy %SourceDrive2%\*.* %destDrive2%\*.* /R:5 /W:3 /Z /XX /TEE /LOG+:%destDrive2%\RoboCopy_Logfile\%destDrive2%_Log.txt
IF '%allDone%'=='2' GOTO end
IF NOT EXIST %destDrive3% MD %destDrive3%
IF NOT EXIST %destDrive3%\RoboCopy_Logfile MD %destDrive3%\RoboCopy_Logfile
echo.%date% -%time% - %SourceDrive3%\*.* - to - %destDrive3%\*.*>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
robocopy %SourceDrive3%\*.* %destDrive3%\*.* /R:5 /W:3 /Z /XX /TEE /LOG+:%destDrive3%\RoboCopy_Logfile\%destDrive3%_Log.txt
GOTO end
:regEdit
IF NOT EXIST C:\TEMP\product_X MD C:\TEMP\product_X
echo.Windows Registry Editor Version 5.00> C:\TEMP\product_X\DisableUNCCheck.reg
echo.;>> C:\TEMP\product_X\DisableUNCCheck.reg
echo.[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]>> C:\TEMP\product_X\DisableUNCCheck.reg
echo."DisableUNCCheck"=dword:00000001>> C:\TEMP\product_X\DisableUNCCheck.reg
regedit /s C:\TEMP\product_X\DisableUNCCheck.reg
GOTO SourceDrive1
:end
echo.%copyMode%Copy Completed
echo.%date% -%time% - %copyMode%Copy Ended>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
echo.---------------------------------------------------------------->>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
echo.>>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt
pause
exit
:saveConfig
FOR /F "tokens=1-2 delims=: " %%B IN ('TIME /t') DO SET time=%%B%%C
FOR /F "tokens=1-4 delims=/ " %%B IN ('DATE /t') DO SET date=%%C%%D%%E
IF /I '%copyMode%'=='robo' goto roboCopySave
IF /I '%copyMode%'=='X' goto xCopySave
:xCopySave
IF NOT EXIST C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves MD C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves
echo.IF NOT EXIST %destDrive1% MD %destDrive1%>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.Saving file: C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.%%date%% - %%time%% - %SourceDrive1%\*.* - to - %destDrive1%\*.*^>^>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.xcopy %SourceDrive1%\*.* %destDrive1%\*.* /d /e /c /r /y>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
IF '%allDone%'=='1' GOTO preStart
echo.echo.IF NOT EXIST %destDrive2% MD %destDrive2%>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.%%date%% - %%time%% - %SourceDrive2%\*.* - to - %destDrive2%\*.*^>^>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.xcopy %SourceDrive2%\*.* %destDrive2%\*.* /d /e /c /r /y>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
IF '%allDone%'=='2' GOTO preStart
echo.echo.IF NOT EXIST %destDrive3% MD %destDrive3%>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.%%date%% - %%time%% - %SourceDrive3%\*.* - to - %destDrive3%\*.*^>^>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.xcopy %SourceDrive3%\*.* %destDrive3%\*.* /d /e /c /r /y>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
GOTO preStart
:roboCopySave
IF NOT EXIST C:\TEMP\product_X\%copyMode%Copy_Saves MD C:\TEMP\product_X\%copyMode%Copy_Saves
echo.IF NOT EXIST %destDrive1% MD %destDrive1%>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.Saving file: C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.IF NOT EXIST %destDrive1%\RoboCopy_Logfile MD %destDrive1%\RoboCopy_Logfile>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.%%date%% - %%time%% - %SourceDrive1%\*.* - to - %destDrive1%\*.*^>^>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.robocopy %SourceDrive1%\*.* %destDrive1%\*.* /R:5 /W:3 /Z /XX /TEE /LOG+:%destDrive1%\RoboCopy_Logfile\%destDrive1%_Log.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
IF '%allDone%'=='1' GOTO preStart
echo.IF NOT EXIST %destDrive2% MD %destDrive2%>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.IF NOT EXIST %destDrive2%\RoboCopy_Logfile MD %destDrive2%\RoboCopy_Logfile>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.%%date%% - %%time%% - %SourceDrive2%\*.* - to - %destDrive2%\*.*^>^>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.robocopy %SourceDrive2%\*.* %destDrive2%\*.* /R:5 /W:3 /Z /XX /TEE /LOG+:%destDrive2%\RoboCopy_Logfile\%destDrive2%_Log.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
IF '%allDone%'=='2' GOTO preStart
echo.IF NOT EXIST %destDrive3% MD %destDrive3%>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.IF NOT EXIST %destDrive3%\RoboCopy_Logfile MD %destDrive3%\RoboCopy_Logfile>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.echo.%%date%% - %%time%% - %SourceDrive3%\*.* - to - %destDrive3%\*.*^>^>C:\TEMP\product_X\TEMP\product_X_Migration_%copyMode%Copy.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
echo.robocopy %SourceDrive3%\*.* %destDrive3%\*.* /R:5 /W:3 /Z /XX /TEE /LOG+:%destDrive3%\RoboCopy_Logfile\%destDrive3%_Log.txt>>C:\TEMP\product_X\Data_Migration\%copyMode%Copy_Saves\%date%_%time%_%copyMode%Copy.bat
GOTO preStart
REM product_X Install Batch Script
REM Created by Trevor Giannetti
REM An unpublished work
REM (March 2012)
Mechanic1264889,
You have a couple of different questions here, I'm going to try to split them up and answer them.
First: Understanding xCopy and all of it's triggers.
There is some good literature, first of all, in the command prompt itself:
> xcopy /?
This will get you a list of the possible triggers you can use.
Else, there is some good literature on the net: xCopy Wiki
Here you will find examples of what you're trying to do.
After reading that information, I believe you need to include /C in your string to avoid stopping when your xCopy finds an error.
xcopy C:\Directory\*.* \\Server\Directory\*.* /S /V /C
This will continue even if it finds an error.
Also, have you tried roboCopy yet?
> robocopy /?
Again, here you will get a list of possible triggers.
As well as this link: roboCopy Wiki
I hope that you find what you're looking for here.