Batch Command DATE & USERNAME vars

Hello there experts,
I have approx 15 users using a piece of client software for on of our apps in here.
One of the files for this s/w needs to be backed up regularly.
Being lazy I do not really want to visit all these machines.
I have set up a batch file which I have placed on each users desktop which copies new versions of the software. So that any time a change is made double clicking on the file will copy the updated s/w to their machines.
I was thinkin I could place a file in their statup menu so that when they start their computers up it would copy the the file (the one that needs to be backed up) to a remote location.

i need the script for a batch file that will copy a file to a remote location and rename it to file_%Username%_%Date%.
Where Username is the username of the currently logged in user
date is the date (no need for time).

so it would have the effect of producing this command :
copy d:\file.txt \\someserver\bckups\file_neil_23_10_2003.txt

Any ideas folks ???

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

neilhomanAuthor Commented:
It is also important to mention that users are running NT/2000/95.

Just to make things difficult.

thanks in advance for any comments.

Hmmmm this is something I tried to do unsuccsesfully yesterday. I want to post so I can steal the answer.    Good luck!

script that make that :

for /F "tokens=2-4 delims=/ " %%f in ('date /T') do copy C:\essai\test.txt C:\essai\test_%USERNAME%_%%f_%%g_%%h.txt

Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

neilhomanAuthor Commented:
I pasted the following at the command prompt :

for /F "tokens=2-4 delims=/ " %%f in ('date /T') do copy C:\essai\test.txt C:\essai\test_%USERNAME%_%%f_%%g_%%h.txt

but I got the following :

%%f was unexpected at this time.

this was on windows nt.

I am trying a few varations now.


Try with the brackets after the 'Do' :

for /F "tokens=2-4 delims=/ " %%f in ('date /T') do (copy C:\essai\test.txt C:\essai\test_%USERNAME%_%%f_%%g_%%h.txt)


Download this little utility called doff.exe from  and use their batch commands --  KISS method.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
neilhomanAuthor Commented:
Having a look at doff now.

thanx for your comment,
neilhomanAuthor Commented:
Here's the solution that appears to be working on NT & 2K.... I havent tried W9x yet.

@echo off
for /f "tokens=1-3 delims=/ " %%a in ('doff mm/dd/yyyy -1') do (
set mm=%%a
set dd=%%b
set yyyy=%%c)
copy file.txt file-%UN%-%dd%%mm%%yyyy%.txt

This copies the file file.txt to another file with the username and date postfixed.

It means that I can get all users to backup there files to one central share.

I will be accepting btomgrant's question as an answer but thanks to all for the help,

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.