Batch file help needed

GEC: Discuss gaming, computers and electronics and venture into the bizarre world of STGODs.

Moderator: Thanas

Post Reply
User avatar
Laird
Friendly Neighbourhood Asshole
Posts: 1707
Joined: 2002-09-16 04:33am
Location: Canada

Batch file help needed

Post by Laird »

I've been given the task of creating a batch file to copy a users "favorites", thats all fine and dandy...(I can copy fine.) my problem is I had can't figure out how to do this with out having it be a specific users name.

Instead of the batch saying something like this.

"Copy C:\Documents and Settings\laird\favorites\ O:\backup"

I need it to automatically do this without having to write each and every indivdual user name for each batch file.

So should it be something like?
"Copy C:\Documents and Settings\"username"\favorites\ O:\backup"

Or

"Copy C:\Documents and Settings\"*.*"\favorites\ O:\backup"?

Help and the answer would be greatly apperciated....
"LairdCorp, where total dominion is our number one goal!"-LairdCorp's Motto
Image
User avatar
Mad
Jedi Council Member
Posts: 1923
Joined: 2002-07-04 01:32am
Location: North Carolina, USA
Contact:

Post by Mad »

Simple method:

Code: Select all

copy "C:\Documents and Settings\%1\favorites\" O:\backup
When you run the batch file, give it the parameter of ther username. So "testbatch laird" would replace %1 with "laird" while "testbatch Administrator" would replace %1 with "Administrator".

To get more complicated, you can try playing around with the FOR command.
Later...
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Post by phongn »

Make a batch file with something like this:

Code: Select all

@ECHO OFF

FOR /R /D %%G IN (*FAVORITES) DO XCOPY /E /Q "%%G" "O:\BACKUP%%~pGFavorites\"
Run that batch program from within the Documents and Settings folder. Test this on a machine that isn't critical first :P It won't copy an empty Favorites folder, unfortunately.
User avatar
Laird
Friendly Neighbourhood Asshole
Posts: 1707
Joined: 2002-09-16 04:33am
Location: Canada

Post by Laird »

Well I got the program running, I just need to know how to get it to activate when a user logs off.(I know I can run it as a scheduled task..when a user logson.).

Any ideas?
"LairdCorp, where total dominion is our number one goal!"-LairdCorp's Motto
Image
User avatar
phongn
Rebel Leader
Posts: 18487
Joined: 2002-07-03 11:11pm

Post by phongn »

Learn the magic of Group Policies, there you will find your answer.
Post Reply