Help with .bat file

J

Joe D

I am trying to use the "rename" command to change the name of a file to one
that contains the date (actually the date 12 hours ago) using a .bat file.

The original file name is "Data.html" and if it is 7 am on July 1st 2009, I
want to rename it "Data Jun09.xls" or "Data 0609.xls"

Any help would be appreciated.
 
P

Pegasus [MVP]

Joe D said:
I am trying to use the "rename" command to change the name of a file to one
that contains the date (actually the date 12 hours ago) using a .bat
file.

The original file name is "Data.html" and if it is 7 am on July 1st 2009,
I
want to rename it "Data Jun09.xls" or "Data 0609.xls"

Any help would be appreciated.

This is tricky with a pure batch file because there are no native console
commands in Windows XP to perform date arithmethic. However, the following
hybrid VB Script/Batch solution will do it for you. You need to adjust Line
[5] to suit your requirements and remove the word "echo" on that line in
order to activate the batch file - but only after you have tested it
thoroughly from a Command Prompt!

[1] @echo off
[2] set inc=-12
[3] set Scr=c:\TempVBS.vbs
[4] echo WScript.Echo DateAdd("h", %inc%, Now()) > %Scr%
[5] for /F "tokens=2,3 delims=/ " %%a in ('cscript //nologo %Scr%') do echo
ren "d:\Data*.xls" "Data %%a%%b.xls"
[6] del %Scr%
 
A

Andrew E.

If you have an intel based board,intel has software to edit those files,go
to intel.com & locate the "Integrator Software"....
 
J

Joe D

Thanks - With a minor adjustment, this worked great.

--
Joe D


Pegasus said:
Joe D said:
I am trying to use the "rename" command to change the name of a file to one
that contains the date (actually the date 12 hours ago) using a .bat
file.

The original file name is "Data.html" and if it is 7 am on July 1st 2009,
I
want to rename it "Data Jun09.xls" or "Data 0609.xls"

Any help would be appreciated.

This is tricky with a pure batch file because there are no native console
commands in Windows XP to perform date arithmethic. However, the following
hybrid VB Script/Batch solution will do it for you. You need to adjust Line
[5] to suit your requirements and remove the word "echo" on that line in
order to activate the batch file - but only after you have tested it
thoroughly from a Command Prompt!

[1] @echo off
[2] set inc=-12
[3] set Scr=c:\TempVBS.vbs
[4] echo WScript.Echo DateAdd("h", %inc%, Now()) > %Scr%
[5] for /F "tokens=2,3 delims=/ " %%a in ('cscript //nologo %Scr%') do echo
ren "d:\Data*.xls" "Data %%a%%b.xls"
[6] del %Scr%
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top