Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

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

$
0
0

I am able to make my .bat script works with "echo" and "set" command lines altogether with robocopy and log file destination 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. Please let me know what I did wrong.

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.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>