Is there a way to automatically show the contents of a directory after a cd change in the windows cmd?

时间:2018-08-22 13:45:03

标签: windows cmd directory command-prompt cd

So i want to change directory and view the new directory contents automatically with out having to type cd folder and then dir on the next line. Is there a way to adjust the settings on the windows cmd prompt such that every time you change directory it lists the contents automatically?

2 个答案:

答案 0 :(得分:3)

是&否。 您可以做的是cdcd & dir的别名:

doskey cd=cd $* ^& dir

请注意,这些别名通常仅对您定义它们的会话可用。要永久使用此别名,请看一下我在底部链接的教程。

说明:

doskey-使用doskey.exe

创建别名/ makro

cd $*-将cd与给别名的参数一起使用

^&-这对两个带有&的命令使用正常的^作为转义字符

dir-在您刚刚移入的目录中创建一个dir


有关doskey的其他信息可以在这里找到:

How to set an alias in Windows Command Line?

Setup Persistent Aliases & Macros in Windows Command Prompt (cmd.exe) using DOSKey


其他警告(感谢@eryksun):

请注意,doskey.exe是控制台输入别名和历史记录功能的命令行界面。

控制台别名是在控制台本身中实现的(即conhost.exe)。它们是按可执行文件名定义的(例如cmd.exepython.exe),在行的开头匹配,并通过ReadFile或{{1}替换由进程读取的文本}。

这意味着您不能通过管道输入别名或在批处理脚本中使用别名。为此,您需要一个自定义批处理脚本。

答案 1 :(得分:0)

Im not 100% sure, i have never done that before but i have seen that you are able to do multiple commands in one line, the way to do this differs slightly depending on operating systems and other factors.

If this is what you are meaning then it has been mentioned and answered previously here

How do I run two commands in one line in Windows CMD?