Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rename directory by date using rename command

Status
Not open for further replies.

wncads

Vendor
Nov 1, 1999
181
US
This should not be so complicated?

I am simply trying to add a line in a batch file to rename a folder to the current date.

e.g.

rename e:\backup ***

where *** should be the command to rename using the date format yyyymmdd

i would have thought it was something like %yyyy%mm%dd but that is not the case?

Keith Buchanan
AplusNetworking.com
keith@aplusnetworking.com
 
You can get the system date from the DATE /T command, assign it to a variable, then rename the directory to that variable. For instance, if DATE /T returns:
Mon 10/16/2006
then the following command used in a batch file:
Code:
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%l-%%j-%%k
would set dt to:
2006-10-16

You should then be able to:
rename e:\backup %dt%
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top