Incorporate a variable into a file path

  • Thread starter Thread starter Baldy
  • Start date Start date
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:\"
------
 
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
 
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.
 
Back
Top