简体   繁体   English

如何从 Windows 中的特定目录运行命令?

[英]How to run a command from specific directory in Windows?

I want to run a command (say dir) from a specific folder.我想从特定文件夹运行命令(比如 dir)。 I tried following but it didn't work.我尝试跟随,但没有奏效。

cd C:\Users\administrator\temp; dir;

I want to check all the directories present inside temp folder.我想检查temp文件夹中存在的所有目录。 How can I write a Windows batch script for that?如何为此编写 Windows 批处理脚本?

You don't need the semi-colon's.你不需要分号。 Just put each command on a new line.只需将每个命令放在一个新行上。

cd C:\Users\administrator\temp
dir

The above works just fine for me.以上对我来说效果很好。

Note, you can also use "pushd" and "popd" to change the current directory, perform some work and then return to where you were.请注意,您还可以使用“pushd”和“popd”来更改当前目录,执行一些工作然后返回到您所在的位置。

This can be done using "&"这可以使用“&”来完成

  • Any number of commands can be executed separated with &可以执行任意数量的命令,用 & 分隔

Example:例子:

cd C:\Users\username & dir & cd C:\logs & dir

If you want run command window from a specific folder.如果要从特定文件夹运行命令窗口。

Click your folder then hold your shift key, then right click you will found option open command window here then click it.单击您的文件夹,然后按住shift 键,然后右键单击您会发现在此处打开命令窗口的选项然后单击它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM