Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using variables in a file path directory in a batch file

I have a reasonably simple question, however i cannot seem to find a solution anywhere.

I'm working with some variables in a batch file, and i would like to change the directory according to the variable.

eg,

variable SET /Jan2000 = a
cd P:\Reference\Data\2000\%a%

When i run the batch file, it just stays in the "2000" folder, it does not go the folder below like i ask. Is there any way to get this to work?

Edit: by request, here is the exact code as it is writtenin the batch file. Thanks for the help.

chdir /D P:\Reference\Data\2000
SET Jan2000 = a
chdir P:\Reference\2000\%a%   
dir
pause
like image 327
Nathan Bush Avatar asked Jul 12 '12 14:07

Nathan Bush


2 Answers

You need to SET your variable.

For example:

SET a=Jan2000
CD P:\Reference\Data\2000\%a%
like image 180
aphoria Avatar answered Sep 28 '22 11:09

aphoria


I can't add much to @aphoria's answer but try this

set a=jan2000
pushd P:\Reference\Data\2000\%a%

Using pushd instead of cd incase there's a problem with changing directory over drives. (I know, the /d switch is for that, but worth a shot).

like image 41
Bali C Avatar answered Sep 28 '22 11:09

Bali C