title: Get a list of files/directories in an open Explorer window in C#
body: <p>I'm trying to pull out the list of files and directories listed in an open Explorer window (in the same order as they're displayed) so that I can look through it, then set focus to a particular item.</p>
  
  <p>I found this code <a href="https://stackoverflow.com/questions/14193388/how-to-get-windows-explorers-selected-files-from-within-c">here</a> that allows me to get the <em>selected</em> items, however I'm not sure if it's possible to use this approach to get <em>all</em> items:</p>
  
  <pre><code>List&lt;string&gt; SelectedFiles() {
      string filename;
      List&lt;string&gt; selected = new List&lt;string&gt;();
      var shell = new Shell32.Shell();
      foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows()) {
          filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
          if (filename.ToLowerInvariant() == "explorer") {
               ((Shell32.IShellFolderViewDual2)window.Document).SelectItem()
              foreach (Shell32.FolderItem item in items) {
                  selected.Add(item.Path);
              }
          }
      }
      return selected;
  }
  </code></pre>
  
  <p>It looks like this Shell32 approach would also allow me to select an item programmatically, which is the other part I'm trying to accomplish. Instead of <code>SelectedItems()</code>, I would call <code>SelectItem()</code>, though I'm not sure how to use that function.</p>
  
  <p>Anyone know of a way to get the list of files/directories from an open Windows Explorer window (and ideally set focus to an item)? Perhaps a P/Invoke kind of thing?</p>