Create and Enter a Directory in Command Prompt

Often while using command prompt, I want to create a directory and enter it. To do this I need to type in the following:

C:\Users\Rahul\Documents\Coding>md mydirectory
C:\Users\Rahul\Documents\Coding>cd mydirectory

This is such basic stuff, you would think that Windows would have functionality to do this with one command... But does it? No.

Which is why I've come up with the ultimate solution... Which is just common sense, really.

  • Open up command prompt and type copy con mdc.cmd.
    This let's you create and edit the file 'mdc.cmd', which is located by default in the System32 Folder.

  • Type @md %1 && cd /d %1, and press enter. These commends basically pass on the first command line argument of mdc.cmd to md, and then chose that directory with cd /d. I like to have the /d switch because it allows us to switch the current drive as well, but it is totally up to you.

  • Press Ctrl+Z and hit enter to stop editing the file.

Now everytime you want to create and enter a directory, just enter mdc mydirectory and Command Prompt will automatically enter mydirectory after creating it.

Comments