Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch script to set a variable with the current path location

How can I set a variable with the current location? For instance, if I get in c:\test and want to set the variable to test and if I get inside c:\test\test2 the variable will be set to test2.

I'm thinking about using a for to get inside a lot of folders and check if some file exists, if the correct file exist I want to set the current folder to a variable so I can copy the path and copy the folder.

The main problem deals with copying the rest of the files is the same folder as the .inf file.

like image 386
massaki Avatar asked Jul 22 '11 11:07

massaki


People also ask

How do I set an environment variable in a batch file?

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 (%).

What does %% mean in batch script?

%%i is simply the loop variable. This is explained in the documentation for the for command, which you can get by typing for /? at the command prompt.

What is the current directory in a batch file?

It is the directory from where you start the batch file. E.g. if your batch is in c:\dir1\dir2 and you do cd c:\dir3 , then run the batch, the current directory will be c:\dir3 .


1 Answers

The current directory is in the "shadow" variable cd.
You could try

set "var=%cd%" 
like image 53
jeb Avatar answered Sep 23 '22 01:09

jeb