BAT文件在当前目录中打开CMD [英] BAT file to open CMD in current directory

查看:1151
本文介绍了BAT文件在当前目录中打开CMD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多脚本,我从命令行交互。每次我需要使用它们,我必须打开一个命令行窗口,复制+粘贴和CD到他们所在的目录的路径。这是冗长乏味的(他们在一个相当深的文件系统,所以输入完整路径是一种疼痛,复制+粘贴更好,但不多)。我试图创建一个.BAT文件,我可以双击,将打开一个新的命令行窗口在.bat文件存在的文件夹,但它不工作。它打开一个新窗口,但工作目录不是.bat文件所在的目录。这是我经过多次谷歌搜索后(我的cmd技能不是那么伟大):

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

我知道从当我使用Linux Konqueror有一个命令行窗口这里功能,这是我想在Windows上获得的效果。

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.

推荐答案

使用以下行创建名为 open_dos_here.cmd 的文件:

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

%~d1
cd "%~p1"
call cmd

将此文件放在任何文件夹。
然后,转到您的发送到文件夹( Win + E ; Alt + D ; shell:sendto ; 输入)。
创建一个指向此open_dos_here.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

然后,在任何文件夹中,选择任何文件或子文件夹。右键单击并选择发送到,然后选择 open_dos_here.cmd 以打开该文件夹中的DOS。

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.

这篇关于BAT文件在当前目录中打开CMD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆