Quantcast
Channel: The Old New Thing
Viewing all articles
Browse latest Browse all 3085

Getting the current selection from an Explorer window

$
0
0

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);
 WScript.StdOut.WriteLine(w.LocationName);
 var sel = w.Document.SelectedItems();
 for (var j = 0; j < sel.Count; j++) {
  var item = sel.Item(j);
  WScript.StdOut.WriteLine(item.Name);
  WScript.StdOut.WriteLine(item.Path);
 }
}

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.


Viewing all articles
Browse latest Browse all 3085

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>