在C#上检测打开的文件夹 [英] Detecting an opening folder on C#

查看:89
本文介绍了在C#上检测打开的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以知道何时打开文件夹吗?我的意思是,如果我手动打开一个文件夹(有资源管理器),我可以得到这个文件夹路径吗?

谢谢

Is there any way to know when a folder is opened? I mean, if I manually open a folder (whith explorer), may I get this folder path?

Thanks

推荐答案

否.没有打开文件夹"之类的操作,因此没有任何可检测的.与其他文件夹操作不同,它只是用户界面的一个隐喻.

您可以使用类System.IO.FileSystemWatcher来检测任何必需的"文件系统操作.
请参阅下面对后续问题的另一个答案.

—SA
No. There is no such operation as "open folder", so there is nothing to detect. It is only a metaphor of the UI, unlike other folder operations.

You can detect any "essential" file system operations though using the class System.IO.FileSystemWatcher.

See another Answer to the follow-up Question posted below.

—SA


没有打开文件夹"之类的东西.当您在资源管理器中看到打开的文件夹"时,它只是用于向您显示该文件夹中的文件的直观表示.除了可视化表示和您自己的代码执行的事件处理相结合之外,您无法检测到有人单击(或双击)文件夹的情况.
There is no such thing as an "open folder". When you see an "open folder" in Explorer, it''s merely a visual representation used to show you ther files in that folder. You can''t detect when someone clicks (or double-clicks) on a folder beyond combination of visual representation and event handling performed by your own code.


回答后续问题:如何从资源管理器获取打开的文件夹?

您可以使用类System.Diagnostics.Process找到Explorer的主窗口.属性System.Diagnostics.Process.MainWindowTitle将为您提供当前打开的文件夹,请参见
http://msdn.microsoft.com/en-us/library/system. diagnostics.process.mainwindowtitle.aspx [ ^ ].

但为什么?资源管理器只是可以访问文件结构的众多应用程序之一.识别资源管理器流程实例的过程太麻烦了,但是有什么用呢?此应用程序没有什么特别的.运行它对系统没有影响.顺便说一句,有许多替代文件管理器,比资源管理器要好得多.无论您使用资源管理器做什么,我都觉得毫无意义.

—SA
Answering the follow-up Question: how to get the open folder from Explorer?

You can locate Explorer''s main windows using the class System.Diagnostics.Process. The property System.Diagnostics.Process.MainWindowTitle will give your the current open folder, see
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowtitle.aspx[^].

But why? Explorer in just one of the many applications which can access file structure. There is too much bothering about identification of the instances of Explorer process, but what''s the use? There is nothing special about this application. Running it makes no difference in the system. By the way, there is a number of alternative file managers, much better then Explorer. Whatever you do with the Explorer, I see no sense.

—SA


这篇关于在C#上检测打开的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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