BAT file to open CMD in current directory

2019-01-29 20:01发布

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.

16条回答
一夜七次
2楼-- · 2019-01-29 20:39

There's more simple way

start /d "folder path"
查看更多
等我变得足够好
3楼-- · 2019-01-29 20:39

As a more general solution you might want to check out the Microsoft Power Toy for XP that adds the "Open Command Window Here" option when you right-click: http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx

In Vista and Windows 7, you'll get that option if you hold down shift and right-click (this is built in).

查看更多
beautiful°
4楼-- · 2019-01-29 20:41

Another solution is to use a shortcut file to cmd.exe instead of a batch file.

Edit the shortcut's start in property to %~dp0.

You achieve the same thing, except it has the Cmd icon (and you can change this).

Some people don't like clicking on batch files without knowing what's in them, and some corporate network drives have a ban on .bat files...

查看更多
唯我独甜
5楼-- · 2019-01-29 20:45

The simplest command to do this:
start

You can always run this in command line to open new command line window in the same location. Or you can place it in your .bat file.

查看更多
劳资没心,怎么记你
6楼-- · 2019-01-29 20:46

Create a file named open_dos_here.cmd with the following lines:

%~d1
cd "%~p1"
call cmd

Put this file at any folder. Then, go to your Send To folder (Win+E; Alt+D;shell:sendto;Enter). Create a shortcut to point to this open_dos_here.cmd

Then, in any folder, select any file or sub-folder. Right-click and select "Send To" and then select open_dos_here.cmd to open the DOS in that folder.

查看更多
放我归山
7楼-- · 2019-01-29 20:46

you can try:

shift + right click

then, click on Open command prompt here

查看更多
登录 后发表回答