?
Solved

Include "Today's Date" in the rename syntax

Posted on 2008-10-02
7
Medium Priority
?
693 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 85

Expert Comment

by:oBdA
ID: 22625166
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
ID: 22625379
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
ID: 22625464
Here is the error message
syntaxerror.doc
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 85

Expert Comment

by:oBdA
ID: 22625559
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
ID: 22625710
We are closer. See attached.

Thanks in advance for your help

syntaxerror2.doc
0
 
LVL 85

Expert Comment

by:oBdA
ID: 22625902
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
ID: 22626232

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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 2 hours left to enroll

752 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