Enabling Directory Name Completion
As mentioned in the previous section, filename completion is enabled by default-the Tab key searches for a filename or folder name matching the characters to the left of the cursor. A similar feature called directory name completion lets you use a different key to match only directory names.
I will show you how to enable directory name completion shortly, but prepare yourself for some strangeness. First, there's the matter of the odd default control key settings:
- By default, name completion is enabled and uses the Tab key, whereas directory name completion is disabled.
- If you run CMD with /f:on on the command line, name completion is enabled but now uses Ctrl+F. Directory name completion is enabled and uses Ctrl+D.
- If you run CMD with /f:off on the command line, both name and directory name completion are disabled.
If you want directory name completion to be enabled all the time on Windows XP, the easiest approach is use the TweakUI tool, which you can download from www.microsoft.com.The setting is on the Command Prompt tab.
You can also edit the Registry to change the default settings on XP,Vista, or Windows 7.The values CompletionChar and PathCompletionChar set the key codes used for name completion and directory name completion, respectively. CMD looks for the values in the key
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
which holds the settings for the current user. If they are not present there, CMD looks in
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor
which sets the default for all users.
CompletionChar and PathCompletionChar are DWORD values that hold a number representing the associated control key. It's easiest to enter these values in decimal, where 1 = Ctrl+A, 2 = Ctrl+B, ... 26 = Ctrl+Z. Some handy values to know are listed here:
Value Key 4 Ctrl+D 6 Ctrl+F 9 Ctrl+I (Tab) 32 Disables completion
To use Ctrl+F for name completion and Ctrl+D for directory name completion, follow these steps:
- Run the Registry editor with the command regedit.
- Open HKEY_CURRENT_USER and find Software\Microsoft\Command Processor.
- Double-click the already-present CompletionChar entry, click Decimal, and enter the number 6. Click OK.
- Select Edit, New, DWORD Value.Type the name PathCompletionChar.
- Double-click the new entry, click Decimal, enter the value 4, and click OK.
- Close the Registry editor and any Command Prompt windows.
From now on, when you start a Command Prompt window, Ctrl+F and Ctrl+D will work.
So you don't get surprised by CMD's behavior at some later date, when Registry settings have been made, CMD follows these rules for enabling name or directory name completion:
- If the Registry value is between 1 and 26, completion is enabled unless you specify /f:off when you run CMD.
- If the Registry value is 32, completion is disabled regardless of the /f option setting.
- If the CompletionChar value is defined as 9 (Tab) and the PathCompletionChar value is not defined, CMD displays the default behavior described earlier.
Now, back to our discussion of how the command prompt environment works.
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