Append Todays date to a file name via batch file

Posted on 2003-11-18
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
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
Question by:Nuggets
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
  • 2

Expert Comment

ID: 9774400

@echo off

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

set dstring=%dstring:/=-%

echo move orders.txt orders_%dstring%.txt



Accepted Solution

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

Expert Comment

ID: 13349028
neat tip. thanks!

Expert Comment

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

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

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

728 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