|
Answer» Hello,
I want to rename my text file with previous date e.g.
Today(19-Nov-2008)..I have created a report file 10_Weeks_Report.txt, now I want to rename this file with suffix as 10 weeks old date i.e. 10 Sep,2008. means 10_Weeks_Report_10-Sep-2008.txt.
Is it possible??
Thanks in advance.One way of course is the most direct:
Code: [Select]ren 10_Weeks_Report.txt 10_Weeks_Report_10-Sep-2008.txt
I suspect however you want to calculate dates. Batch language has no way of doing date and time arithmetic. You could use any of the Windows script languages, but many people seem to think that scripting is too close to PROGRAMMING. Uggh!
I've never use the FDATE utility, but I've seen it recommended on these boards. Good luck. Here is a batch script COMBINED with VBS which will do date calculations returning today's date or adding or subtracting a number of days. It's set to subtract 70 days, the ten weeks period asked for, but could be set to any number, or the number could be entered as a variable.
The majority of this was written by dias de verano then hacked around by me.
Code: [Select]:: Dias de verano.
echo off cls
:: Create/run vbs file (extracts date components) & set variables.. :: ------------------------------------------------------------------- :start set vbsfile=%temp%\newdate.vbs echo Newdate = (Date()-70)>%vbsfile% echo Yyyy = DatePart("YYYY", Newdate)>>%vbsfile% echo Mm = DatePart("M" , Newdate)>>%vbsfile% echo Dd = DatePart("D" , Newdate)>>%vbsfile% echo Wd = DatePart("WW" , Newdate)>>%vbsfile% echo Wn = DatePart("Y" , Newdate)>>%vbsfile% echo Ww = datepart("W" , Newdate)>>%vbsfile%
echo Wscript.Echo Yyyy^&" "^&Mm^&" "^&Dd^&" "^&Wd^&" "^&Ww^&" "^&Wn>>%vbsfile%
FOR /F "tokens=1,2,3,4,5,6 delims= " %%A in ('cscript //nologo %vbsfile%') do ( set Year=%%A set Month=%%B set Day=%%C set Week#=%%D set Weekday#=%%E set Day#=%%F ) del %vbsfile%
for /f "Tokens=%month%" %%A in ( "Jan Feb Mar Apl May Jun Jly Aug Sep Oct Nov Dec") do ( set alfamonth=%%A )
for /f "Tokens=%weekday#%" %%A in ( "Sun Mon Tue Wed Thu FRI Sat") do ( set alfaday=%%A )
:: [Environment Variables are: :: %Year% in the format yyyy :: %Month% in the format m or mm :: %Day% number of the day in month in the format d or dd :: %Week#% in the format w or ww (range 1 thru' 52) :: %Weekday#% day number in week in the format w :: (range 1 thru' 7, day#1 is Sunday) :: %Day#% day number in the year in the format d thru ddd :: (range 1 thru' 366) :: %alfamonth% month in the format Jan Feb....etc :: %alfaday% day in the format Sun Mon....etc]
echo New-Year is %year% New-Month is %month%/%alfamonth% New-Day is %day%/%alfaday%
set newdate=%day%-%alfamonth%-%year%
ren 10_Weeks_Report.txt 10_Weeks_Report_%newdate%.txt
Good luck
|