?
Solved

Include "Today's Date" in the rename syntax

Posted on 2008-10-02
7
Medium Priority
?
699 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 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

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…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

850 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