删除包含图像的目录 [英] Delete Directory That Contains Images

查看:110
本文介绍了删除包含图像的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好
我正在尝试删除包含图像的目录
这些图像是我将它们保存在源代码中的,它们在程序启动时会重新加载

Hello
I''m trying to delete a directory that contains images
those images I saved them in it in source code them I reloaded them when the program begins

foreach (string file in files)
                   {

                       File.SetAttributes(file, FileAttributes.Normal);
                       try
                       {
                           File.Delete(file);
                       }

                       catch
                       {
                       }
                   }
                   Directory.Delete(username)



但是我想我需要删除在wpf中很难建立的图像,然后再删除文件
我总是得到目录不是空的
如果删除try catch,则会得到文件正在被另一个进程使用"

我该如何解决这个问题?
谢谢



But I guess I need to dispose Images which I found it hard to establish in wpf before deleting the files
I always get that the Directory isn''t empty
and if I remove the try catch I get " the files are being used by another process"

How can I sold this problem?
Thanks

推荐答案

通常,您无法删除当前正在使用的文件和文件夹.


使用的含义是:就像Sergey所说的,文件可以由另一个进程打开,因此,在该文件关闭该文件之前,您无法删除该文件.

在首先删除其所有内容之前,不能删除文件夹,因此,如果文件被锁定,则该操作将失败.
Generally you cannot delete files and folders which are being used currently.


What being used means: Like Sergey said a file can be opened by another process and hence you cannot delete it until that file has been closed by that process.

A folder cannot be deleted until all its contents have been deleted first, hence if a file is locked then the operation will fail.


通过此代码,我可以'看不出是什么问题.如果您尝试删除不为空的目录,请尝试以下操作:
From this code I can''t see what is the problem. If you try to delete a directory that is not empty try this:
Directory.Delete(path, true);


如果第二个参数为true,则将删除路径中的目录,子目录和文件.


If second parameter is true, you will remove directories, subdirectories, and files in path.


这篇关于删除包含图像的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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