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?
Yes & No.
What you can do, is make cd
and alias for cd & dir
:
doskey cd=cd $* ^& dir
Note that these aliase are by standard only avaible for the session you define them. To use this alias persistent take a look at the tutorials I linked at the bottom.
Explanation:
doskey
- create an alias/makro using doskey.exe
cd $*
- Use cd
with the argument given to the alias
^&
- This uses the normal &
for two commands with the ^
to as escape character
dir
-make an dir
in the directory you just moved in
Additional info about doskey
can be found here:
How to set an alias in Windows Command Line?
Setup Persistent Aliases & Macros in Windows Command Prompt (cmd.exe) using DOSKey
Additional warning (Thanks to @eryksun):
Note that doskey.exe
is a command-line interface to the console's input alias and history facilities.
Console aliases are implemented in the console itself (i.e conhost.exe
). They're defined per executable name (e.g. cmd.exe
or python.exe
), match at the beginning of a line, and replace the text that's read by the process via ReadFile
or ReadConsole
.
This means you cannot pipe into an alias or use one in a batch script. For that you need a custom batch script.