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

x
?
Solved

Batch Command DATE & USERNAME vars

Posted on 2003-10-23
8
Medium Priority
?
1,760 Views
Last Modified: 2013-12-28
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_neil_23_10_2003.txt

Any ideas folks ???


0
Comment
Question by:neilhoman
  • 4
  • 2
  • 2
8 Comments
 

Author Comment

by:neilhoman
ID: 9606431
It is also important to mention that users are running NT/2000/95.

Just to make things difficult.

thanks in advance for any comments.

-Neil
0
 
LVL 1

Expert Comment

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

Btomgrant
0
 
LVL 1

Expert Comment

by:lacams
ID: 9632653
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:neilhoman
ID: 9633455
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

0
 
LVL 1

Expert Comment

by:lacams
ID: 9633785
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


0
 
LVL 1

Accepted Solution

by:
btomgrant earned 750 total points
ID: 9639310
Download this little utility called doff.exe from http://www.jfitz.com/dos/  and use their batch commands --  KISS method.

btomgrant
0
 

Author Comment

by:neilhoman
ID: 9641732
Having a look at doff now.

thanx for your comment,
-Neil
0
 

Author Comment

by:neilhoman
ID: 9641843
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%.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,

-Neil
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

879 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