BAT file to open CMD in current directory

FrustratedWithFormsDesigner picture FrustratedWithFormsDesigner · Dec 15, 2010 · Viewed 188.1k times · Source

I have many scripts which I interact with from the command line. Everytime I need to use them, I have to open a command line window and copy+paste and CD to the path to the directory they are in. This is tedious (they are in a rather deep file system, so typing out the full path is a pain, copy+paste is better but not much). I tried to create a .BAT file that I could double-click on that would open a new command-line window in the folder the .bat file exists in but it does not work. It opens a new window, but the working directory is not the directory that .bat file is in. Here's what I've got after much googling (My cmd skills ain't so great):

cd %CD%
cmd.exe

I know from when I used Linux that Konqueror had a "Command-line window here" feature, and that's the effect I'm trying to get on Windows.

Answer

Chris picture Chris · Dec 15, 2010

you probably want to do this:

cd /d %~dp0
cmd.exe

this will set your current directory to the directory you have the batch file in