码迷,mamicode.com
首页 > 其他好文 > 详细

取消文件夹下的子文件夹和文件的只读属性

时间:2017-09-13 14:08:12      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:only   inf   zip   search   har   解决   http   file   author   

private void UnsetReadOnly(string dirPath)
{//http://bbs.csdn.net/topics/380233913
string[] dirPathes = Directory.GetDirectories(dirPath, "*.*", SearchOption.AllDirectories);
string[] filePathes = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories);
foreach (var dp in dirPathes)
{
DirectoryInfo dir = new DirectoryInfo(dirPath);
dir.Attributes = FileAttributes.Normal & FileAttributes.Directory;
}
foreach (var fp in filePathes)
{
File.SetAttributes(fp, System.IO.FileAttributes.Normal);
}
}

 

用ICSharpZipLib解压,如果目标文件夹里的文件为只读属性会导致解压失败:UnauthorizedAccessException: Access to the path is denied.

使用如上代码取消文件的只读属性后解决.(只设置文件夹的Attributes为非只读没作用,里面的文件还是只读)

取消文件夹下的子文件夹和文件的只读属性

标签:only   inf   zip   search   har   解决   http   file   author   

原文地址:http://www.cnblogs.com/xuejianxiyang/p/7514477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!