The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,308 other followers

batch-file trick: Starting Windows Explorer and selecting a file (“explorer” commandline parameters “/n” “/e” “/select” “/root” “/start” site:microsoft.com)

Posted by jpluimers on 2010/09/01

From a batch-file I recently had to start Windows Explorer, at the same time select a specific file or directory.

This turned out pretty easy: use the /select command-line switch from Windows Explorer.

In fact, Windows Explorer has a few command-line switches, and the “explorer” commandline parameters “/n” “/e” “/select” “/root” “/start” site:microsoft.com query will find quite a few topics about it:

The fun is: the Windows Explorer command-line syntax has been consistent since Windows 95:
Syntax:

  • explorer [/n] [/e][,/root,object][[,/select],subobject]

Parameters:

  • /n
    Always open a new window (even if the specified folder is already open).
  • /e
    Use Windows Explorer view. The default is Open view.
  • /root, object
    Specify the object in the normal namespace that will be used as the root of this Windows Explorer Folder. The default is to just use the normal namespace root (the desktop).
  • subobject
    Specify the folder to receive the initial focus unless /select is used. The default is the root.
  • /select
    Specifies that the parent folder is opened and the specified object is selected.

So: the solution was easy:

explorer /select,%FileNameToSelect%

or (note the comma after the /e)

explorer /e,/select,%FileNameToSelect%

Note that this syntax will not select the file, but in stead try to open the default application for FileNameToStart:

explorer %FileNameToStart%

–jeroen

One Response to “batch-file trick: Starting Windows Explorer and selecting a file (“explorer” commandline parameters “/n” “/e” “/select” “/root” “/start” site:microsoft.com)”

  1. […] I suspect there are many more magic GUID values you could use for other functions because the built-in syntax has been there for a long time. […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: