Welcome to MSDN Blogs Sign in | Join | Help

Hirlpoo West

Notes (technical and not so technical) from the Microsoft Field.

Syndication

News

Postings here are provided
"AS IS" with no warranties
and confer no rights.

View Derek Dysart's profile on LinkedIn


Windows Command Line Auto Completion

Having explained this to a number of people in as many days, I thought I'd share this tip for working with long paths on the command line.  The easist way to expalin this is to jump in feet first:

  • Open a command line (<Windows Key>-R, CMD<Enter> is engrained in my hands at this point in my career)
  • At the prompt, repeatedly hit tab

You will be cycling through all of the files and directories in your current directory.  Now try this:

  • At a clean command prompt, type "dir \P" then start hitting tab. 

Now you'll be cycling through all the directories that start with "P" in the root of the current drive (in my case, it cycles through "Program Files" then Projects).  You'll also notice that for files with embedded spaces, quotes are automatically added.  This works for as many characters as you wish to type. After you cycle to the directory you want, type a backslash, then hit tab again and you'll cycle through the files and sub-directories in that directory, and so on.  On my current machine, I can type the following to open my machine.config:

notepad \win<tab>\mic<tab>\<tab>\v1.1<tab>\con<tab>\m<tab><enter>

This results in the following command line, which would take considerably more keystrokes  or mouse clicks:

notepad \WINDOWS\Microsoft.NET\Framework\v1.1.4322\config\machine.config

This works at just about any point in a command, as long as you are starting from a space.  It will also work on UNC paths staring at the share name (Assuming you can authenticate to that particular share):

dir \\fileserver\share\<tab>

There may be a delay as CMD goes an enumerates the items on the share, but if you are trying to get to something deep down in some huge directory structure with really long path names, this helps a ton.

Though this has been in CMD for some time, I don't think it was enabled by default untill Windows XP which may explain why it isn't well known. If you're stuck on a Windows 2000 box (or, gasp! NT4), you can edit the registry to enable this (Standard registry disclaimer applies - don't do this unless you know what you're doing since you can render a box un-bootable with sufficient registry tweaking.): 

Set HKCU\Software\Microsoft\Command Processor\CompetionChar to 9

KB244407 covers this in detail.

I used to hate the command line becuase I'm lazy and didn't want to type out huge paths (which I would end up misspelling).  No longer!

Published Thursday, August 03, 2006 2:58 PM by ddysart

Filed under:

Comments

# Command line path trick < m0t0r&#8217;s Society @ Saturday, August 05, 2006 3:22 PM

PingBack from http://m0t0rsociety.org/blog/?p=171

Command line path trick < m0t0r’s Society

# re: Windows Command Line Auto Completion @ Monday, August 07, 2006 9:25 PM

Great info!  These kinds of information gems are priceless.

Matt Ridings

# Windows Command Line Auto Completion : Techtips @ Monday, August 07, 2006 11:50 PM

PingBack from http://techtips.chanduonline.com/2006/08/07/windows-command-line-auto-completion/

Windows Command Line Auto Completion : Techtips

# ' + title + ' - ' + basename(imgurl) + '(' + w + 'x' + h +') @ Tuesday, August 08, 2006 5:13 AM

PingBack from http://blog.msrportal.com/index.php/archives/windows-command-line-auto-completion/

' + title + ' - ' + basename(imgurl) + '(' + w + 'x' + h +')

# DOS time-saver - sitegenerationtools.com @ Tuesday, August 08, 2006 6:23 AM

PingBack from http://sitegenerationtools.com/2006/08/08/dos-time-saver/

DOS time-saver - sitegenerationtools.com

# re: Windows Command Line Auto Completion @ Tuesday, August 08, 2006 11:03 AM

Set the key in HKLM for 2k, thus you don't have to import the key for each user (and can be set remotely).

Windows Registry Editor Version 5.00

; This is only necessary for Windows 2000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"CompletionChar"=dword:00000009

The more useful registry hack under XP is Command Prompt Here

Windows Registry Editor Version 5.00

; This gives Right-Click Command Prompt access to folders
; This does not support UNC pathnames

[HKEY_CLASSES_ROOT\Folder\shell\Command]
@="Command &Prompt"
[HKEY_CLASSES_ROOT\Folder\shell\Command\command]
@="cmd.exe \\\"%1\\\""

Bucky

# re: Windows Command Line Auto Completion @ Tuesday, August 08, 2006 11:06 AM

Alternate version (works when right clicking on folders in Explorer)

Windows Registry Editor Version 5.00

; This gives Right-Click Command Prompt access to folders
; This does not support UNC pathnames

[HKEY_CLASSES_ROOT\Folder\shell\Command]
@="Command &Prompt"
[HKEY_CLASSES_ROOT\Folder\shell\Command\command]
@="cmd.exe /k \"cd %L\""

Bucky

# Tab completion on the Windows command line at backwhack - tech news web 2.0 style @ Wednesday, August 09, 2006 6:31 AM

PingBack from http://www.backwhack.com/2006/08/07/tab-completion-on-the-windows-command-line/

Tab completion on the Windows command line at backwhack - tech news web 2.0 style

New Comments to this post are disabled
Page view tracker