检查文件夹是在使用的C# [英] Check if folder is in use in C#

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

问题描述

考虑一个网络文件夹:

\\ desiis \ C $ \企业\的B2B \显示器

在该机器上,任何试图删除目录过程显示器收到一个错误,因为局域网上的用户有目录打开(有可能与Windows资源管理器)。

On that machine, any process that tries to delete the directory Monitor receives an error because a user on the LAN has that directory open (likely with Windows Explorer).

我能察觉,通过C#和.NET框架,如果任何用户(和它的用户)有一个特定的目录打开/使用?

Can I detect, via C# and .NET framework, if any user (and which user) has a particular directory open/in use?

推荐答案

我不知道,如果你能得到的目录中的特定用户,但在C#.NET DirectoryInfo类很可能是最好的一段路要走。

I'm not sure if you can obtain the particular user in the directory but the DirectoryInfo class in C# .NET would probably be the best way to go.

http://msdn.microsoft.com/en-us/library/system.io.directoryinfo%5Fmembers.aspx

查看这个链接的API,你会发现有一个方法来获取当目录最后一次访问,但不是谁的信息。你也可以尝试删除目录,因为它不可用时捕获任何异常(异常会被抛出,你可能非常了解)。

Review the API at this link and you'll notice there is a method to get the information about WHEN the directory was last accessed but not by who. Also you can catch any exception when trying to delete a directory as it being unavailable (an exception will be thrown as you are probably well aware).

另外请注意,异常捕获是昂贵的,你应该这样做评估的过程中的任何速度的下降。

Also note that exception catching is costly and you should evaluate any slowdowns in your process by doing this.

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

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