Solved Adding file extension in Batch Process

February 25, 2013 at 07:27:57
Specs: Windows 7
Greetings all, I have another batch file question, if anyone could help.
I have a text file that I would like to add last weeks date range to, and would like to have this done by a batch file.
the format to look like this:
Test020313to020913.txt

any thoughts?


See More: Adding file extension in Batch Process

Report •


#1
February 25, 2013 at 10:45:22
✔ Best Answer
Pick a language that isn't batch. Both VBScript and PowerShell have date/time math, batch does not.

How To Ask Questions The Smart Way


Report •

#2
February 25, 2013 at 15:13:55
While avoiding batch is almost always the best answer, if it doesn't solve your issue it's probably not THE best answer. Speak more about your problem, and we'll see how it goes. For instance, what relationship does this date range have to the modified file date/time?

How To Ask Questions The Smart Way


Report •

#3
February 25, 2013 at 21:05:20
here's a vbscript rendition:
'==== begin vbscript "week.vbs"
'option to allow override of current date, else delete line and just use "date" for dd
if wscript.arguments.count=1 then dd=wscript.arguments(0) else dd=date
z=dateadd("d",-7-(datepart("w",dd)-1) mod 7,dd)
'split week beg & end-date elements (dmy) into array "p"
p=split(z&"/"&dateadd("d",z,6),"/")
'format for output: all elements two-digits zero-padded
for i=0 to 5
p(i)="0"&p(i)
p(i)=right(p(i),2)
next
'output looks like: 02/10/13/02/16/13 when inputdate is range 2/17-2/23
wscript.echo join(p,"/")
'===== end vbscript
batch:
for /f "tokens1-6 delims=\" %%a in ('cscript /nologo week.vbs') do set name=%%a%%b%%cto%%d%%e%%f
echo %name%

Report •

Related Solutions

#4
February 26, 2013 at 07:20:31
Powershell version:
$someDate = Get-Date
$SoW = $SomeDate.AddDays(-$someDate.DayOfWeek.value__)
"{0:MMddyy}to{1:MMddyy}" -f $SoW, $SoW.AddDays(6)

How To Ask Questions The Smart Way


Report •


Ask Question