Getting the current working directory from DOS or Batch file
In the world of batch files I’ve been trying for ages to work out how to get the current/present working directory to make the batch script I’m working on a bit more flexible.
In Unix it’s easy, just call ‘pwd’ and you have it. I wasn’t expecting something that simple in Windows but it is! A call to ‘cd’ is all that’s needed. If you need to set it in a batch script the following line does the trick:
|
|
set WORKING_DIRECTORY=%cd% |
I was surprised that something so simple (I do now feel like an idiot) wasn’t easier to find on Google. I ended up going via Experts Exchange (how they end up with such high search results when you have to pay to see the information is beyond me) and several other verbose ways of solving the problem before finally coming across this article which explained it.
-
http://andyp-tw.blogspot.com Andy
-
Reshmi
-
David
-
anonymous
-
Adam Pond
-
Ben Luplow
-
Ben Luplow
-
Ron Patrick
-
SenHu
-
http://amitbhatia.in Amit Bhatia
-
Ben Luplow
-
Agostino
-
Scott D
-
Mark
-
Jon
-
Mike Vasiljevs
-
Chupakabra
-
llbbl
-
Pratap Reddy
-
veggen