windows batch script for copy file and paste into other directory

//open notepad and paste below then save as mytest.bat


rem *mytest.bat

rem *Boobalan 15/10/2020

rem *copy this file ABC.DEFGH.IJK to this place C:\Users\boobalan.rajaram\Desktop\Target\


for /f "tokens=1-6 delims=/ " %%i in ('date /t') do (set day=%%i& set month=%%j&set year=%%k)

for /f "tokens=1-4 delims=:. " %%b in ('time /t') do (set hr=%%b& set mm=%%c& set ss=%%d)

IF %hr% LSS 10 ( SET hr1=0%hr%) ELSE (SET hr1=%hr%)

for /F "tokens=1-2 delims= " %%a IN ("%hr1%") DO (SET hr1=%%a%%b)


set source=C:\Users\boobalan.rajaram\Desktop\Source\ABC.DEFGH.IJK

set destin=C:\Users\boobalan.rajaram\Desktop\Target\

set log=C:\Users\boobalan.rajaram\Desktop\ABC.DEFGH.IJK.log.txt


echo %year%%month%%day%%hr1%%mm% Process %source%  START >> %log%


echo "*******Copy process starting********" >> %log%


set filename=ABC.DEFGH.IJK

echo %filename% >> %log%


set filenameTS=%filename%.%year%%month%%day%%hr1%%mm%

echo "New file name is ->" %filenameTS% >> %log%

set destination=%destin%%filenameTS%

copy %source% %destination% >> %log%


if exist %destination% goto SUCCESS


echo "*******Copy failed******* " >> %log%


goto END


:SUCCESS

echo "*******Copy succeeded******* " >> %log%

del %source%  >> %log%


:END

echo "*******Copy process end******* ">> %log%

exit

Post a Comment

0 Comments