Quantcast
Channel: Windows Server 2012 – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 53

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

$
0
0

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


Filed under: Power User, Windows, Windows 10, Windows 7, Windows 8, Windows 8.1, Windows 9, Windows 95, Windows 98, Windows ME, Windows NT, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server 2016, Windows Vista, Windows XP

Viewing all articles
Browse latest Browse all 53

Trending Articles