Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Append Todays date to a file name via batch file

Posted on 2003-11-18
4
Medium Priority
?
4,421 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 200 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

885 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