Solved

Include "Today's Date" in the rename syntax

Posted on 2008-10-02
7
672 Views
Last Modified: 2011-10-19
How can I incorporate the current date in a rename command on my "C" drive. This command is run from a .bat file which looks like the following:

Y:
cd \AERS\Raw_Data
Rename tblExpense-RawData.csv tblExpense-RawData_last.csv

I would like to replace "last" to look like tblExpense-RawData_10022008.csv

0
Comment
Question by:arnier13
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Try the following; I took the liberty of changing the resulting date format to yyyymmdd, because it makes for better sorting of the resulting file names.
It's currently in test mode, it will only display the "rename" command, and not run it, so that you can test the script. Remove the capitalized ECHO to run it for real.
The syntax of creating "your" date based on the variable %date% should be obvious if you want to have a different order after all.

Y:

cd \AERS\Raw_Data

set MyDate=%Date:6,4%%Date:0,2%%Date:3,2%

ECHO Rename tblExpense-RawData.csv tblExpense-RawData_%MyDate%.csv

Open in new window

0
 

Author Comment

by:arnier13
Comment Utility
I'm getting a syntax error when I try this.

Y:
cd \AERS\Raw_Data
set MyDate=%Date:6,4%%Date:0,2%%Date:3,2%
Rename tblExpense-RawData.csv tblExpense-RawData_%MyDate%.csv

I did remove the "echo" statement in front of the "Rename" command
0
 

Author Comment

by:arnier13
Comment Utility
Here is the error message
syntaxerror.doc
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Sorry, missed some tildes:
Y:

cd \AERS\Raw_Data

set MyDate=%Date:~6,4%%Date:~0,2%%Date:~3,2%

ECHO Rename tblExpense-RawData.csv tblExpense-RawData_%MyDate%.csv

Open in new window

0
 

Author Comment

by:arnier13
Comment Utility
We are closer. See attached.

Thanks in advance for your help

syntaxerror2.doc
0
 
LVL 82

Expert Comment

by:oBdA
Comment Utility
Please post the output of
echo %date%
in a command prompt.
Note that you don't need to take a screen shot; you can pick "Edit" from the Window menu, then highlight and copy the output to the clipboard, and enter it directly here.
0
 

Accepted Solution

by:
arnier13 earned 0 total points
Comment Utility

Y:\SS Createam\Production3\Batch_Jobs>Y:

Y:\SS Createam\Production3\Batch_Jobs>cd \AERS\Raw_Data

Y:\AERS\Raw_Data>echo Thu 10/02/2008
Thu 10/02/2008

Y:\AERS\Raw_Data>set MyDate=/02/Th 1

Y:\AERS\Raw_Data>Rename tblExpense-RawData.csv tblExpense-RawData_/02/Th 1.csv
The syntax of the command is incorrect.

Y:\AERS\Raw_Data>More
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now