打开时删除文件夹 [英] Delete a folder when it open

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

问题描述

VB.NET



我想使用以下代码删除文件夹。通常它可以工作但是当测试文件夹打开时,下面的代码有一个例外。



VB.NET

i want to delete a folder using below code. Normally it works but when the testfolder is open, below code got an exception.

My.Computer.FileSystem.DeleteDirectory("testfolder", FileIO.DeleteDirectoryOption.DeleteAllContents)





有没有办法删除文件夹,即使该文件夹已打开。



我尝试过:



尝试过几个删除方法,没有人工作。



is there any way to delete the folder even when the folder is open.

What I have tried:

tried several delete method, no one worked.

推荐答案

不,如果文件夹是打开的,这意味着应用程序正在使用其中的文件 - 你不能删除该文件夹而不会弄乱该应用程序。



使用 try ... catch 块来捕获异常,告诉用户,并在他关闭文件时让他有机会重新尝试。
No, if the folder is open, that means that an application is using a file in it - and you can't delete the folder without messing up that app.

Use a try...catch block to catch the exception, tell the user, and give him a chance to re-try when he has closed the file.


Quote:

有什么办法可以删除文件夹,即使文件夹是打开的。

is there any way to delete the folder even when the folder is open.



不,这是防止操作系统的工作它会发生。

唯一的办法是让所有其他应用程序关闭他们在该文件夹中打开的文件。


No, it is the OS job to prevent it to happen.
The only way to do it is the have all other apps to close the files they opened in that folder.


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

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