如何识别是否打开文件夹? [英] How to identify whether folder is opened?

查看:210
本文介绍了如何识别是否打开文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我试图重命名文件夹,但是如果在Windows资源管理器中打开该文件夹,我得到一个 IOException 。如何确定是否在C#中的Windows资源管理器中打开文件夹?

解决方案

捕获IOException?正如其他人所说的那样,只要试着做你想做的事情,如果发生了异常,就采取适当的行动,不管你的情况如何。



您没有太多的选择,我认为:

pre code> bool iHaveAccess = CheckAccess(文件夹);
if(iHaveAccess)
{
RenameFolder(folder,newFolderName);

如果在CheckAccess成功并调用RenameFolder之后会发生什么事情会锁定文件夹?那要怎么办?


In my application I'm trying to rename the folder, but if the folder is opened in Windows Explorer I get an IOException. How can I identify whether folder is opened in Windows Explorer in C#?

解决方案

catch the IOException?

As others have said, just try to do what you want, catch the exception if it happens and take appropriate action, whatever that is in your context.

You don't really have much choice as I see it, consider:

bool iHaveAccess = CheckAccess(folder);
if (iHaveAccess)
{
    RenameFolder(folder,newFolderName);
}

what happens if between CheckAccess succeeding and calling RenameFolder something else locks the folder? Whatcha gonna do then?

这篇关于如何识别是否打开文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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