neilhoman
asked on
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
and
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_n eil_23_10_ 2003.txt
Any ideas folks ???
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
and
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_n
Any ideas folks ???
Hmmmm this is something I tried to do unsuccsesfully yesterday. I want to post so I can steal the answer. Good luck!
Btomgrant
Btomgrant
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
christophe
for /F "tokens=2-4 delims=/ " %%f in ('date /T') do copy C:\essai\test.txt C:\essai\test_%USERNAME%_%
christophe
ASKER
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.
-N
for /F "tokens=2-4 delims=/ " %%f in ('date /T') do copy C:\essai\test.txt C:\essai\test_%USERNAME%_%
but I got the following :
%%f was unexpected at this time.
this was on windows nt.
I am trying a few varations now.
-N
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)
christophe
for /F "tokens=2-4 delims=/ " %%f in ('date /T') do (copy C:\essai\test.txt C:\essai\test_%USERNAME%_%
christophe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Having a look at doff now.
thanx for your comment,
-Neil
thanx for your comment,
-Neil
ASKER
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)
set UN=%USERNAME%
copy file.txt file-%UN%-%dd%%mm%%yyyy%.t xt
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,
-Neil
@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)
set UN=%USERNAME%
copy file.txt file-%UN%-%dd%%mm%%yyyy%.t
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,
-Neil
ASKER
Just to make things difficult.
thanks in advance for any comments.
-Neil