Solved

Include "Today's Date" in the rename syntax

Posted on 2008-10-02
7
678 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 83

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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 83

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 83

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

778 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