Vb.net:重命名目录失败,并且“访问路径xxx被拒绝” [英] Vb.net: renaming a directory fails with "access to the path xxx denied"

查看:135
本文介绍了Vb.net:重命名目录失败,并且“访问路径xxx被拒绝”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家晚上好,



我正在尝试从VB.NET程序重命名目录:



Good Evening everyone,

I'm trying to rename a directory from a VB.NET program:

Call FileIO.FileSystem.RenameDirectory("D:\some\subdir\structure\OldName", "NewName")





很简单,没什么复杂的。抛出异常



Very simple, nothing complicated. It throws an Exception

"Access to the path '...\OldName' denied"





我尝试过:



这不是安全/许可问题。

这不是一个只读的问题。

这不是网络问题,一切都是本地的。

目录或其子目录中没有打开的句柄



我知道因为我可以在资源管理器或命令行中重命名该目录,即使我的Visual Studio在异常时位于调试器中。



网上有很多类似的问题,但原因总是上面提到的,这里不适用。



我真的很想让这个工作。好吧,我总是可以用RENAME命令生成一个命令行,但这有点矫枉过正:-)



最好的问候,



Christof



更新:.NET方法和Win32 API MoveFile和MoveFileEx函数失败,目录名称包含2个或更多句点。喜欢



What I have tried:

It's NOT a security/permission problem.
It's NOT a Read-Only problem.
It's NOT a network problem, everything is local.
There are NO open handles in the directory or its subdirectories

I know because i CAN rename the directory in Explorer or at the command line, even while my Visual Studio is sitting in the debugger at the exception.

There are lots of similar questions in the Net, but the cause is always one of the above mentioned, which do not apply here.

I would really like to get this working. Well, i could always spawn a command line with the RENAME command, but this is a little bit overkill :-)

Best Regards,

Christof

UPDATE: .NET methods and Win32 API MoveFile and MoveFileEx functions fail the directory name contains 2 or more periods. Like

Folder 2.1.1



资源管理器可以毫无问题地重命名它。嗯......即使最低级API函数失败,它是如何做到的?!


Explorer can rename it without a problem. Hmmm ... how is it doing this if even the lowest level API functions fail ?!?

推荐答案

找到罪魁祸首:刚刚停止OneDrive,一切正常。得到了这个想法,因为即使工作重命名也非常缓慢地传播到其他资源管理器窗口,甚至从右窗格传播到树视图窗格。所以我开始怀疑shell扩展。重新启动OneDrive没有带回错误,所以这不是一个真正的最终和最后的测试,但也许只有在OneDrive运行几天后才会发生。谁知道呢?



更新:不,OneDrive在目录中没有打开句柄(至少HANDLE告诉过我),它甚至没有包含在OneDrive中文件夹。
Found the culprit: Just stopped OneDrive and everything works. Got the idea because even the working renames propagated very slowly to other Explorer windows' or even from the right pane to the treeview pane. So i started to suspecting shell extension. Restarting OneDrive did not bring back the error, so this is not really a final and concluding test, but maybe it only happens after OneDrive runs for some days. Who knows?

UPDATE: No, OneDrive hadn't a handle open in the directory (at least HANDLE told me so), it is not even included in the OneDrive folder.


已停止文件历史记录,它可能已解决问题
Stopped File History and it may have solved the problem


这篇关于Vb.net:重命名目录失败,并且“访问路径xxx被拒绝”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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