Name Completion
When you are typing command lines to CMD, you often need to type file and folder names. Name completion makes this easier-you can type just the first few letters of a file or folder name, strike a control key, and CMD finishes typing the name for you. This is a nifty but not widely known feature that, like most of the other fun new features in CMD, Microsoft has borrowed from the Unix operating system.
Here's how name completion works: If you press the filename-completion character (usually the Tab key), CMD examines the characters to the left of the cursor and uses this as the basis for a path and/or filename.The way to think of this is that when you type the completion character, CMD looks for any files whose names start with whatever you've typed so far. If there is a space or nothing at all to the left of the cursor, CMD looks for * (all files).
If CMD finds no matching file or folder name, it beeps and does nothing. If it does find a matching name, CMD finishes typing the name for you. It looks like this:
c:\batchglt; ← edit b I type edit and the letter b, then press Tab
c:\batchglt; ← edit bills.bat CMD finds a matching file and completes the name
If this is the correct name, you can continue typing on the command line.This is a great timesaver! If the name that CMD types is not the one you are looking for, you can press the completion key again to see the next matching name. Pressing the key repeatedly cycles through all matching names.What's more, you can hold down the Shift key while typing the completion character to cycle backwards.
Tip: If you have to type a long pathname such as \Users\bknittel\Documents, you can use name completion for each part of the name. For this example, you could type the following:
dir \u (Tab) \b (Tab) \d (Tab) (Tab)
Try this on your own computer (and use your own username instead of bknittel). It's pretty slick- CMD adds the required quotation marks and moves them into the correct positions automatically.
Directory name completion works in an identical fashion, except that it matches only folder names. Name completion is enabled by default, but not directory name completion. If you're content enough to use the Tab key to cycle through both filenames and folder names, just leave everything as it is. If you want to use a separate key to indicate that you want CMD to look only for directory names, I show you how in the next section.
In this tutorial:
- The CMD Command-Line
- CMD Versus COMMAND
- Running CMD
- Opening a Command Prompt Window with Administrator Privileges
- CMD Options
- Disabling Command Extensions
- Command-Line Processing
- Console Program Input and Output
- Using the Console Window
- I/O Redirection and Pipes
- Copy and Paste in Command Prompt Windows
- Command Editing and the History List
- Name Completion
- Enabling Directory Name Completion
- Multiple Commands on One Line
- Grouping Commands with Parentheses
- Arguments, Commas, and Quotes
- Escaping Special Characters
- Configuring the CMD Program
- The Search Path
- Changing the Path
- Predefined and Virtual Environment Variables
- Setting Default Environment Variables
- Built-in Commands
- Extended Commands
- Listing Files with the Dir Command
- Paginating Long Listings
- Printing Directory Listings
- Sorting Listings
- Locating Alternate File Streams
- Setting Variables with the Set Command
- Conditional Processing with the if Command
- Scanning for Files with the for Command
- Using the for Command's Variable
- Processing Directories
- Numerical for Loop
- Getting More Information