How to Open a Window's Command Prompt to a Particular (non default) Directory
Some programs, created for windows, offer a command line interface that you may want to frequent for performing certain tasks. Sometimes, using their command line interface requires you to open a command prompt and navigate to the program's root folder using dos commands. This article explains how to eliminate having to manually navigate to a program's root folder, by automating this task, with a batch file shortcut.
If you open a command prompt in windows (by clicking the Start Menu | clicking Run | typing: cmd | clicking "OK"), the command prompt's default location will be your user directory. The prompt will look something like this:
C:\Documents and Settings\UserName>
If you want to change directories, you can use the cd command. For example, if you wanted to move the command prompt to your "program files" directory, you could type:
cd "C:\Program Files"
Now the prompt will look like this:
C:\Program Files>
This is simple and easy, however, there are 3 reasons you may want to automate this process with a batch script:
- The "directory you desire to move to" has a long name that is cumbersome to type.
- The "directory you desire to move to" is very deep in the file system's hierarchy, which again, requires more typing.
- You frequent the directory so often, that you don't want to type its location each time.
By creating a simple batch script you'll be able to open a command window whose prompt is already at the directory you want.
Open Microsoft Notepad (Start Menu | All Programs | Accessories | Notepad).
Cut and paste the following into Notepad:
@ECHO OFF
cmd /k cd "C:\Program Files"
Save this file with a ".bat" file extension instead of the (default) ".txt" extension: File | Save As | choose location (such as the desktop) | type "AnyName.bat" in the File name box *with quotes* | click "Save".
Now, go to where you saved the batch file (you've just created). Double clicking it should bring up a command window whose command prompt is already at the "Program Files" directory (we specified in the batch file).
I use batch files (like above) to quickly get to the command directories of (the window's versions of) MySQL and Matisse databases. I even use a keyboard management software so that I may hit a hot key, on my keyboard, and have the desired prompt immediately in front of me.
Tell others about
this page:
About the Author
Lonnie Best has been using the internet since 1993, and has been making web pages since 1995. visit: http://www.lonniebest.com
Comments? Questions? Email Here