删除文件夹时出错. [英] Error Deleting Folder.

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

问题描述

在我们的应用程序中,为项目创建了一个文件夹.
当我尝试在"Windows资源管理器"中删除该文件夹时,允许我将其删除.

我想发生的是,当我尝试删除该文件夹时,发生类似于无法删除文件.文件正在被另一个进程使用"的错误.

谢谢!

In our application a folder is created for a project.
When I try to delete that folder in "Windows Explorer" it''s allowing me to delete it.

What I want to happen is that an error occurs analogous to "Can''t delete file. File is being used by another process", when i try to delete that folder.

Thank you!

推荐答案

防止用户删除文件夹的唯一方法是通过进程打开该文件夹中的文件(我认为在只读的文件夹也可能有效).

警告:删除文件夹时,文件系统首先尝试删除该文件夹中的文件,而所有文件都被删除后,它将尝试删除该文件夹.它会按照写入磁盘的顺序删除文件,因此它可能在删除文件之前删除其他文件,这将阻止文件系统删除文件夹.

添加了示例(ManfredRBihy):
The only way to prevent the user from deleting a folder is by having a file in that folder opened by a process (I think setting a file in the folder to be read only may also work).

Caveat: When you delete a folder, the file system first tries to delete files in the folder, and when all of them are deleted, it tries to delete the folder. It deletes files in the order they were written to the disk, so it might delete other files BEFORE it gets to the file that will prevent the file system from deleting the folder.

Example added (ManfredRBihy):
StreamWriter sw = null;
StreamWriter firstSW = null;
for (int idx = 0; idx < 10; idx++)
{
    String fileName = String.Format("C:\\temp\\Manfred\\subfolder\\{0}.txt", idx);
    sw = new StreamWriter(File.Open(fileName, FileMode.Create));
    sw.Write(fileName);
    if (idx == 0)
        firstSW = sw;
    else
    {
        sw.Close();
        sw.Dispose();
    }
}
Console.WriteLine("Writing all files finished");
Console.WriteLine("Deletion of folder will fail. Hit enter!");
Console.ReadLine();
firstSW.Close();
firstSW.Dispose();
Console.WriteLine("Deletion of folder will now succeed! Hit enter");
Console.ReadLine();


示例结束


只需验证..,该Floder已开始被您的应用程序使用.
或您的应用程序正确关闭..,请正确关闭您的应用程序,然后尝试删除..,

确保没有其他应用程序正在使用此选框..,

谢谢
just verify .., That Floder is begin used by your application.
or your application closed Properly.., Close your Application Properly and try to delete..,

Make sure that any other applications are not using this floder..,

Thanks


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

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