A colleague came to my rescue on this. He created a VB script for this that also runs the dir command. Here is the content of that:
Dim getDate, getDay, getMonth, getYear, oShell, setPath, Response, Yesterday
Set oShell = CreateObject("WScript.Shell")
getDate = Date()-1
getDay = Day(Yesterday)
getMonth = Month(Yesterday)
getYear = Year(Yesterday)
Yesterday = getYear & "-" & getMonth & "-" & getDay
setPath = "cmd /c dir path /variables >FileToPipeResultsTo" & Yesterday & "FileExtension"
I don’t know of an easy way to do it using a BAT. You could need to program the date calculation by yourself in a similar way that the one used here.
Another option could be to have another bat scheduled to run daily, which writes the current date to a file, and then your other script reads the file created the day before.
In other words, one day, some script does this:
echo %date% > c:\previous_date.txt
And the next day, your script reads the file, and use that value to rename the desired files.
for /f %%a in (c:\previous_date.txt) do (