Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign chdir to a variable in .bat?

I'm trying to translate a bash script into a .bat script. The specific line I'm tripping over is this:

X=`pwd`

What is the .bat equivalent?

I need to take the directory that the script is currently running in as a variable so I can use a generic relative path to find files in the directory. I'm running on Windows-XP in the command prompt.

like image 902
Owen Pierce Avatar asked Jul 24 '09 18:07

Owen Pierce


People also ask

What is %% A?

%%a are special variables created by the for command to represent the current loop item or a token of a current line. for is probably about the most complicated and powerful part of batch files. If you need loop, then in most cases for has you covered.

What does %% bat mean?

%%a refers to the name of the variable your for loop will write to. Quoted from for /? : FOR %variable IN (set) DO command [command-parameters] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used.

Can you use variables in batch files?

When creating batch files, you can use set to create variables, and then use them in the same way that you would use the numbered variables %0 through %9. You can also use the variables %0 through %9 as input for set. If you call a variable value from a batch file, enclose the value with percent signs (%).


1 Answers

The current directory is available in the pseudo-variable %cd%. So:

set X=%cd%

stores it in a variable named X.

like image 54
Ben M Avatar answered Sep 19 '22 15:09

Ben M