Solved

Include "Today's Date" in the rename syntax

Posted on 2008-10-02
7
681 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 84

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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 84

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 84

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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