为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

C# 递归剔除文件夹以及文件包括只读文件)

2017-11-28 3页 doc 14KB 13阅读

用户头像

is_597436

暂无简介

举报
C# 递归剔除文件夹以及文件包括只读文件)C# 递归剔除文件夹以及文件包括只读文件) C# 递归删除文件夹以及文件(包括只读文件) 以下代码示例是用来删除文件夹以及文件(其文件包括只读文件)分享给大家,也许可能对 大家多少有一点帮助. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; usi...
C# 递归剔除文件夹以及文件包括只读文件)
C# 递归剔除文件夹以及文件包括只读文件) C# 递归删除文件夹以及文件(包括只读文件) 以下代码示例是用来删除文件夹以及文件(其文件包括只读文件)分享给大家,也许可能对 大家多少有一点帮助. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace filedelete { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public const string TARGET_PATH = @ C:\Iris-2 ; private void Form1_Load(object sender, EventArgs e) { DeleteFolder(TARGET_PATH); } /// summary /// 递归删除子文件夹以及文件(包括只读文件) /// /summary /// param name= TARGET_PATH 文件路径 /param public void DeleteFolder(string TARGET_PATH) { //如果存在目录文件,就将其目录文件删除 if (Directory.Exists(TARGET_PATH)) { foreach (string filenamestr in Directory.GetFileSystemEntries(TARGET_PATH)) { if (File.Exists(filenamestr)) { FileInfo file = new FileInfo(filenamestr); if (file.Attributes.ToString().IndexOf( ReadOnly ) != -1) { file.Attributes = FileAttributes.Normal;//去掉文件属 性 } File.Delete(filenamestr);//直接删除其中的文件 } else { DeleteFolder(filenamestr);//递归删除 } } System.IO.DirectoryInfo DirInfo = new DirectoryInfo(TARGET_PATH); DirInfo.Attributes = FileAttributes.Normal FileAttributes.Directory; //去掉文件夹属性 Directory.Delete(TARGET_PATH, true); } } } }
/
本文档为【C# 递归剔除文件夹以及文件包括只读文件)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索