155 pts.
 Date Calculation
I am needing to rename files based on the previous day's date. I am looking for help in calculating this taking into account the number of days in a given month. I.e. If I run the script on March 1st, the date in the name will need to be Feb. 28th. I am currently using Windows batch files. I have seen some WSH examples that seem to do the calculation more efficiently (less lines of code) but we are not that strong in WSH to support this - yet. Any help is appreciated.

Software/Hardware used:
ASKED: May 22, 2009  4:09 PM
UPDATED: May 22, 2009  7:42 PM

Answer Wiki:
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: <pre> 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 <i>path</i> <i>/variables</i> ><i>FileToPipeResultsTo</i>" & Yesterday & "<i>FileExtension</i>" oShell.Exec setPath ------------------------------------------------------------------------------------------------ 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 <a href="http://www.computing.net/answers/windows-xp/delete-files-older-then-xdays-v2/171309.html">here</a>. 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: <pre>echo %date% > c:previous_date.txt</pre> And the next day, your script reads the file, and use that value to rename the desired files. <pre>for /f %%a in (c:previous_date.txt) do ( set previous_date=%%a exit /b )</pre> ------------------------</pre>
Last Wiki Answer Submitted:  May 22, 2009  7:42 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _