以编程方式对 Windows 8 上的文件夹进行排序

Programmatically sort folders on Windows 8

Windows 8 似乎不会在单个文件夹上保留排序顺序。我猜想什么时候 explorer.exe 终止(比如重启时)这些首选项会被丢弃?打败我,我所知道的是一段时间后(比如几天)这些偏好完全消失了。

有没有办法在 Windows 资源管理器中复制以编程方式排序的文件夹(选择上下文菜单中的 'Sort by' 选项之一)?

例如,假设我在 Windows UI 中打开了一个文件夹。假设文件夹当前设置为按 'Name' 排序,在 运行 将按大小排序的程序之后,我再次检查 Windows Explorer 中的排序顺序,现在显示 'Size'?

我有一个很大的文件夹结构,我希望它的所有文件夹及其子文件夹按大小永久排序。所以我想 运行 这个程序在查看它们之前不必先单独手动重新排序它们。谢谢!

排序顺序属于视图,而不是文件夹。您可以在同一个文件夹上打开两个 Windows Explorer windows,每个都有不同的排序顺序。

要在 Windows Explorer 导航到特定文件夹时强制排序,请首先挂钩该实例的 DShellWindowsEvents::WindowRegistered event on the shellwindows object, then each time when the WindowRegistered event triggers, enumerate through the shell window list and compare with your existing enumeration to find the new windows explorer instance. Once you get hand on the new instance, hook up the DWebBrowserEvents2::DocumentComplete 事件以侦听其导航。

导航完成后,DocumentComplete 事件将为您提供目标 URL,您可以使用它来检测目标是否在您的大文件夹结构中。如果是,请从 windows 资源管理器实例查询 IShellBrowser 服务,然后调用 QueryActiveShellView to get the shell view. Once you get the shell view, QI for IFolderView2 and then call SetSortColumns.

The Automate the Active Windows Explorer or Internet Explorer Window sample on codeproject has most of the code, except that it calls IShellView::SelectItem to simulate SHOpenFolderAndSelectItems 最后。

您可以通过按住 CTRL 并单击右上角的 X 来保存资源管理器排序设置。

http://blog.chron.com/helpline/2009/01/saving-explorer-sort-order/