Solved

Append Todays date to a file name via batch file

Posted on 2003-11-18
4
4,419 Views
Last Modified: 2008-11-10
I need to create a batch file that will append todays date to a file name and then move it to a different location.  I understand the basics of moving the file to a new location but I am a total loss of how to append date to the file.  An example would be

orders.txt --> orders_11-18-2003.txt
or
orders.txt --> orders_111803.txt

I am not to particular on the format as long as it is consistent.

Thanks in advance for the help
0
Comment
Question by:Nuggets
  • 2
4 Comments
 
LVL 6

Expert Comment

by:mrdtn
ID: 9774400

@echo off
setlocal

for /f "tokens=2" %%v in ("%date%") do set dstring=%%v

set dstring=%dstring:/=-%

echo move orders.txt orders_%dstring%.txt

--

mrdtn
0
 
LVL 6

Accepted Solution

by:
mrdtn earned 50 total points
ID: 9774425
Remove the "echo" at the beginning of the move command when you are ready to go operational.
0
 

Expert Comment

by:amyot
ID: 13349028
neat tip. thanks!
0
 

Expert Comment

by:JeanGenie
ID: 22922483
I cant get this to work - it says the syntax is incorrect - I have used same code just different file names.

setlocal
for /f "tokens=2" %%v in ("%date%") do set dstring=%%v
set dstring=%dstring:/=-%
move e:\db\test\oe_backups\file1.txt  e:\db\test\secure_backups\file2_%dstring%.txt
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Combine multiple text files into one file 4 48
Create a specific short cut with a parameter. 2 197
Date variable in batch file 2 26
How to remove unwanted words? 34 34
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…
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…
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 …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

14 Experts available now in Live!

Get 1:1 Help Now