"For" command line in bat file does not work in task scheduler

  • Thread starter Thread starter dcsck
  • Start date Start date
D

dcsck

I am able to make my .bat script works with "echo" and "set" command lines in the bat file by using raykor suggestion for putting .bat file in program/script and put the path in "start in" field. However, "for" command line stops all other command lines to execute. Please see the script below. Please help how to make the "for" command line to work. I need to add date and time to the file/folder name in order to keep track of a copy of file on each day. This script works perfectly when I execute line by line one at a time on CMD command prompt. It copied file and folders and gave me date and time and concatenated to the file/folder name. The first 2 lines do not work. if I delete the first 2 lines, it works fine.


for /f "Tokens=1,2,3,4* Delims=/" %i IN ('date/t') do set dt=%i%j%k%l
for /f "Tokens=1,2*" %i in ('time /t') do set tm=-%i%j
set tm=%tm::=-%
set dtt=%dt%%tm%
echo Copying backup set: %dtt%.
echo Please wait...
robocopy s:\data2 d:\testBackup\data2 /e /mir /np /tee /log:"c:\users\myusername\desktop\backup_log.txt"
echo Finished.

Continue reading...
 
Back
Top