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:
~ </td> | set WORKING_DIRECTORY=%cd%~ </td> </tr> </tbody></table> 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. |
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.