开发者

Check if folder is in use in C#

开发者 https://www.devze.com 2022-12-14 08:26 出处:网络
Consider a network folder: \\\\desiis\\c$\\Company\\B2b\\Monitor On that machine, any process that tries to delete the directory Monitor receives an error because a user on the LAN has that director

Consider a network folder:

\\desiis\c$\Company\B2b\Monitor

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).

Can I detect, via C# and .NET 开发者_开发知识库framework, if any user (and which user) has a particular directory open/in use?


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_members.aspx

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.


No, there is no possibility I know.

It seems you'll have to catch the occuring Exception as a workaround.

0

精彩评论

暂无评论...
验证码 换一张
取 消