TechTricks
Technical answers from the trenches 
 
 
 
 

     
   
Windows Trick: Faster Directory Changes in Command Prompt
 
   
 Posted: 17 April 2003
 
   
 
 Applies to: Windows 2000 and later
 
   
 
Audience: Everyone
 
       
   

Question: Is there a shortcut for changing directories using the Command Prompt?

Answer: Yes, if you're using Window 2000 or later. Use the asterisk wildcard (*) to abbreviate directory names. This article shows several examples and describes possible problems you might encounter.

Overview

If, like us, you use the Command Prompt (e.g. COMMAND or CMD) to administer or maintain your Windows PC, there's a little documented trick for changing directories, one that's particularly helpful for multi-word folder names or deeply nested ones. Use the asterisk (*) wildcard character to abbreviate the target directory.

Instead of typing the full directory path, use an asterisk (*) to abbreviate it, as shown in the following Example:

Example 1: Using abbeviations to change directories
C:\>cd\pr*

C:\Program Files>

You can use combine abbreviations to change to nested directories, as shown in Example 2:

Example 2: Using multiple abbreviations
C:\>cd \pr*\bo*\d*\p*

C:\Program Files\Borland\Delphi6\Projects>

This trick helps if you tend to work with several different versions of Windows throughout the day, each running different versions of the operating system. For example, Example 3 will change to the WINNT\ directory under Windows 2000 and the WINDOWS\ directory under Windows XP:

Example 3: Changing to WINNT\ or WINDOWS\, as appropriate
C:\>cd\win*

C:\WINNT>

Choose Abbreviations Carefully:

When using this trick, use abbreviations specific enough to resolve to the target directory. The next example illustrates one result of careless abbreviations:

Example 4: Careless abbreviations
C:\>cd\

C:\>cd\w*

C:\WINNT>cd s*
The system cannot find the path specified.

C:\WINNT>dir s* /ad
 Volume in drive C has no label.
 Volume Serial Number is 0000-0000

 Directory of C:\WINNT

04/01/2003  10:56a      <DIR>          security
04/10/2003  09:59a      <DIR>          ShellNew
02/19/2002  06:30a      <DIR>          Speech
02/19/2002  05:25p      <DIR>          system
04/15/2003  12:11p      <DIR>          system32
               0 File(s)              0 bytes
               5 Dir(s)  18,340,470,784 bytes free

Example 4 failed because s* resolves to more than one folder. As Example 5 shows, longer abbreviations can help.

Example 5: Longer abbreviations are more effective.
C:\WINNT>cd sy*

C:\WINNT\system>

This works...unless you wanted to change to \SYSTEM32. Example 6 shows a different approach that handles this case more appropriately:

Example 6: A different way to use abbreviations
C:\WINNT>cd s*2

C:\WINNT\system32>

Careless abbreviations can also lead to unusual (or unexpected, at the very least) error messages, as shown in Example 7:

Example 7: Carelessly changing to \PROGRAM FILES
C:\>cd\p*
The process cannot access the file because it is being used by another
process.

Now, if you're fairly familiar with Windows, this may seem like an unusual error message for the CD command to report. Example 8 shows why this happened:

Example 8: Understanding Example 7
C:\>dir p*
 Volume in drive C has no label.
 Volume Serial Number is 0000-0000

 Directory of C:\

04/10/2003  09:50a      <DIR>          Program Files
               0 File(s)              0 bytes
               1 Dir(s)  18,340,470,784 bytes free

C:\>dir /ah p*
 Volume in drive C has no label.
 Volume Serial Number is 0000-0000

 Directory of C:\

04/15/2003  12:11p         402,653,184 pagefile.sys
               1 File(s)    402,653,184 bytes
               0 Dir(s)  18,340,470,784 bytes free

C:\>cd pagefile.sys
The process cannot access the file because it is being used by another
process.

Example 8 reveals that Windows (or the Command Prompt) evaluates the available filenames for use with this shortcut. We assume it does this by performing a DIR command in the background and then evaluating the results for directory matches. To perform that test, though, it needs to access the file. Since pagefile.sys is almost always in use, the error appears.

Summary

In short, the asterisk wildcard character can help you change directories more quickly in the Command Prompt. While you have to use it carefully, it can be a tremendous time saver once you get used to using it.

Please note that we've only tested this with Windows 2000 and XP. We're not sure this trick works in older versions of Windows. If you find it does, please drop us a note via the Feedback link. We'll update the article accordingly and give you credit for the find.

 

       

Top

Feedback About Paradox Delphi Assorted Web Stuff
 
 
Copyright © 2000-2004, techtricks.com; All Rights Reserved.
Acknowledgements, Disclaimers, Terms and Conditions.
Article last updated on 31 May 2003

 

Other Sites: Paradox, Delphi, Perl, Web Stuff, and More


 

[- End -]