Getting the current selection from an Explorer window

Raymond Chen

Today’s Little Program prints the current selection in all open Explorer windows. (This is an alternative to the C++ version that involves a ridiculous amount of typing.)

var shellWindows = new ActiveXObject(“Shell.Application”).Windows();
for (var i = 0; i < shellWindows.Count; i++) {
 var w = shellWindows.Item(i);
 var sel = w.Document.SelectedItems();
 for (var j = 0; j < sel.Count; j++) {
  var item = sel.Item(j);

I have no idea why you would want to do this, but there you have it. (If you want the focused item rather than the selection, then get the Focused­Item property.)

Okay, maybe you can use this as a quick-and-dirty way to get the parsing name for a shell item: Open an Explorer window, select the item you are interested in, then run the script to see what gets printed out as the Path.


Discussion is closed.

Feedback usabilla icon