Link to home
Start Free TrialLog in
Avatar of Nuggets
Nuggets

asked on

Append Todays date to a file name via batch file

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
Avatar of mrdtn
mrdtn


@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
ASKER CERTIFIED SOLUTION
Avatar of mrdtn
mrdtn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
neat tip. thanks!
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