tags:

views:

127

answers:

2

How can a batch file by itself see where it is located?

+1  A: 

Just call "cd"

set WORKING_DIRECTORY=%cd%

Used to be %~dp0, but that's not working for me in Vista.

Chris Doggett
That's not the location of the cmd file, it's the working directory when you run it, which is not the same thing: "cd \" followed by "\directory\x.cmd" will have %cd% set to "\", not "\directory".
paxdiablo
no, this is a piece of shit (sorry) above works great.
YourComputerHelpZ
+9  A: 

%0 is the name of the file. %~dp0 will be the absolute location of the file, with d being the drive, p being the path, and 0 being the filename.

rpkelly
Thanks! This works fine!
YourComputerHelpZ