Want to read a text file and do copy of the Files
Posted: 06 Feb 2018 04:56
I want to read a text file and its looks like
my text file backupfilenameandlocation.txt
Read the above file line by line and copy the files in my dat format created folder.
Here I want handle the error while during the copy
Errorlevel is not working properly on my for loop
It's returing always 0 if the file is not exists also
I want to handle the error if anything happened wrong while the copy it needs to come out of the for loop and as well my script and send a error message.
Can anyone help me on this...
My Bat script
my text file backupfilenameandlocation.txt
Code: Select all
C:\Users\SVCT-WI-Jenkins\Desktop\Scripts_for_ORF2\5_cur_sys_filebackup.bat
C:\Users\SVCT-WI-Jenkins\Desktop\Scripts_for_ORF2\5_cur_sys_backup.bat
C:\Users\SVCT-WI-Jenkins\Desktop\Scripts_for_ORF2\24_Service_up.ba
C:\Users\SVCT-WI-Jenkins\Desktop\ORF2_Deployments\CAM8_Hotfix_Deployment_Instruction_CAM8_6.20.8.5.txtt
Here I want handle the error while during the copy
Errorlevel is not working properly on my for loop
It's returing always 0 if the file is not exists also
I want to handle the error if anything happened wrong while the copy it needs to come out of the for loop and as well my script and send a error message.
Can anyone help me on this...
My Bat script
Code: Select all
REM *********************Take the Backup Of Current System******************************************************************
REM @echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
set "datestamp=%YYYY%%MM%%DD%" & set "timestamp=%HH%%Min%%Sec%"
set "fullstamp=%YYYY%%MM%%DD%_%HH%%Min%%Sec%"
set "backup_location=C:\Users\SVCT-WI-Jenkins\Desktop\backup_location"
set "destination=%backup_location%\%fullstamp%"
mkdir %destination%
SetLocal EnableDelayedExpansion
::This line is just in case n has been defined before the batch file is run
Set n=
Set InputFile=C:\Users\SVCT-WI-Jenkins\Desktop\Scripts_for_ORF2\Input_File_For_Deployment\backupfilenameandlocation.txt
For /F "tokens=*" %%I IN (%InputFile%) DO (
XCOPY %%I %destination% /E /V /I /Y
echo %errorlevel%
if NOT %errorlevel%==0 ( exit /b 2 )
)
:: This line will display the variables just assigned
:: For testing only, delete when not needed
EndLocal