递归删除C#中的文件和目录 [英] Recursive delete of files and directories in C#

查看:54
本文介绍了递归删除C#中的文件和目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#中递归删除给定目录?包含文件的目录.

How to delete a given directory recursively in C# ? A directory containing files.

应该 System.IO.Directory.Delete使用第二个参数 true 可以解决问题吗?

Should the System.IO.Directory.Delete with the second parameter true do the trick?

因此,尽管这里的答案更加明确,但实际上我确实回答了我自己的问题.首先我要问这个问题的原因是,完全具有调用 Delete (第二个参数设置为 true 的代码)的代码并未按照预期的方式运行在做.事实证明,其原因是目录层次结构中某处某个文件的某个位置设置了 RO 属性,而Windows XP的 Polish 版本为此抛出了一个非常奇怪的消息.

So, I actually did answer my own question, although the answers here were a little more clarifying. The reason for me asking this in the first place was that the code that has exactly that invocation of Delete (2nd param set to true) was not doing what it was supposed to be doing. As it turned out the cause of that was that there was a file somewhere down in the the directory hierarchy with RO attribute set, and the Polish version of Windows XP was throwing a really strange message for that.

推荐答案

是的,这就是该参数的要点.您尝试过并遇到任何问题吗?(我已经仔细检查过了,它对我来说很好用.)

Yup, that's the point of that parameter. Did you try it and have any problems? (I've just double-checked, and it works fine for me.)

这篇关于递归删除C#中的文件和目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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