|Quote=JMR: How about if I want to date it as of yesterday?|
Or, if it is not too much to ask, I want to date it as of the previous working day so that if today is monday, the file date will change to last friday.
I hope you're not gonna come up with any more surprises LOL.
The following batch script/VB script should do what you want but it does NOT cater for national or local holidays where if Friday is a hol it doesn't change the date to the previous working day and if Monday is a holiday, when the script is run on Tuesday the filedate will be changed to Monday. You must change the indicated line to reflect your filename. Not fully tested.
> %vbs% echo WScript.Echo Date
for /f "tokens=*" %%a in ('cscript //nologo %vbs%') do set savdate=%%a
echo Newdate = Date
echo Wn = DatePart("W" , Newdate^)
echo Wscript.Echo Wn
FOR /F "tokens=1" %%A in ('cscript //nologo %vbs%') do (
If !weekday#! equ 1 set backdate=2&goto cont
if !weekday#! equ 2 set backdate=3&goto cont
> %vbs% echo WScript.Echo DateAdd("d",-%backdate%,Date)
for /f "tokens=* delims=" %%a in ('cscript //nologo %vbs%') do set newdate=%%a
:: Set filename to reflect YOURS
:: Alter system date and file amended date
echo %newdate% echo.|date> nul
copy %filename%,,+> nul
:: Restore system date
echo %savdate% echo.|date> nul
Warning: During the few microseconds the date is changed to Newdate any file created/updated/accessed may show the date(s) as the Newdate. Also any program which uses the date (e.g. to name backups) could use the Newdate instead of the current date. Please check this out when testing the script.
Wish you good luck
Edited to add warning and post updated script after some testing.