How to create a yesterday date in a batch

batch-filedatems-dos

copy \\server01\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server02\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server03\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server04\E$\LogFiles\IVR\bcR\??120428.* \\LBC\workgroup\cs\ftp\Team\bcR\

This is my current script and I have to change the date weekly. I am looking for a script that will look at today's current date minus one day and can modify the 12 04 28. (Year Month Day sample 120408). I need yesterday's date. This script is in DOS

Best Answer

Save yourself a world of pain, use a better language!

Here is the script you want in PowerShell:

$yesterday = [DateTime]::Today.AddDays(-1).ToString("yyMMdd")
copy \\server01\E$\LogFiles\IVR\bcR\??${yesterday}.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server02\E$\LogFiles\IVR\bcR\??${yesterday}.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server03\E$\LogFiles\IVR\bcR\??${yesterday}.* \\LBC\workgroup\cs\ftp\Team\bcR\
copy \\server04\E$\LogFiles\IVR\bcR\??${yesterday}.* \\LBC\workgroup\cs\ftp\Team\bcR\

Use these instructions to help you schedule the copy