在 Windows 8 上以编程方式对文件夹进行排序 [英] Programmatically sort folders on Windows 8

查看:25
本文介绍了在 Windows 8 上以编程方式对文件夹进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Windows 8 does not seem to persist sort orders on individual folders. I'm guessing when explorer.exe terminates (like when rebooting) these preferences get discarded? Beats me, all I know is after a time (like a few days) those preferences get totally lost.

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

Is there a way to duplicate programmatically sorting folders in Windows Explorer (opting one of the 'Sort by' options in the context menu)?

这样,假设我在 Windows UI 中打开了一个文件夹.假设文件夹当前设置为按名称"排序,在运行按大小排序的程序后,我再次检查 Windows 资源管理器中的排序顺序,现在显示大小"?

Such that, say I have a folder opened in the Windows UI. Say the folder is currently set to sort by 'Name' and after running the program which will sort it by size I check the sort order in Windows Explorer again and it now says 'Size'?

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

I have a certain big folder structure that I want all of it and its subfolders sorted by size permanently. So I would like to run this program before viewing them and not have to individually manually re-sort them all first. Thanks!

推荐答案

排序顺序属于视图,而不是文件夹.您可以在同一个文件夹中打开两个 Windows 资源管理器窗口,每个窗口都有不同的排序顺序.

The sort order belongs to the view, not folder. You can have two Windows Explorer windows open on the same folder, each has a different sort order.

要在 Windows 资源管理器导航到特定文件夹时强制排序,首先将 DShellWindowsEvents::WindowRegistered 事件在 shellwindows 对象,然后每次触发WindowRegistered事件时,通过shell窗口列表进行枚举,并与你现有的枚举进行比较,找到新的windows explorer实例.掌握新实例后,连接 该实例的 DWebBrowserEvents2::DocumentComplete 事件以侦听其导航.

To force a sort order when Windows Explorer navigates to a specific folder, first hook the 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 event for that instance to listen to its navigations.

导航完成后,DocumentComplete 事件将为您提供目标 URL,您可以使用该 URL 来检测目标是否在您的大文件夹结构内.如果是这样,请从 Windows 资源管理器实例查询 IShellBrowser 服务,然后调用 QueryActiveShellView 获取外壳视图.一旦你获得了 shell 视图,IFolderView2 的 QI 然后调用 设置SortColumns.

When a navigation is complete, the DocumentComplete event will give you the target URL which you can use to detect if the target is inside your big folder structure. If so, query the IShellBrowser service from the windows explorer instance, then call QueryActiveShellView to get the shell view. Once you get the shell view, QI for IFolderView2 and then call SetSortColumns.

自动化 Active Windows Explorer或 codeproject 上的 Internet Explorer Window 示例 包含大部分代码,除了它调用 IShellView::SelectItem 模拟 SHOpenFolderAndSelectItems 最后.

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 at the end.

这篇关于在 Windows 8 上以编程方式对文件夹进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆