Incorporate a variable into a file path

B

Baldy

Does anybody know how to incorporate a variable into a
file path in a batch file? Thanks

This is the furthest i got:

-----
@echo off

SETSTRING STRING2="user"

xcopy "C:\Documents and Settings\%STRING2\Favorites" "Z:\"
------
 
D

David H. Lipman

Try

set Win2K_User=John

xcopy "C:\Documents and Settings\%Win2K_User%\Favorites" "Z:\"



If the batch file is called MyFav.bat

You can also try

%0 %1 %2
MyFav.bat John Z:\ <--batch file being called

xcopy "C:\Documents and Settings\%1\Favorites" "%2" <-- line in batch file

Dave
 
P

Pegasus \(MVP\)

Baldy said:
Does anybody know how to incorporate a variable into a
file path in a batch file? Thanks

This is the furthest i got:

-----
@echo off

SETSTRING STRING2="user"

xcopy "C:\Documents and Settings\%STRING2\Favorites" "Z:\"
------

If you open a Command Prompt and type the command

set

then you will see that you already have an environmental
variable for what you want. It is called %userprofile%.

There are many other variables there that will be of interest
for you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top