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

去除文件的只读属性:

private void UnsetReadOnly(string dirPath)
{//
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);
}
}

System.IO.File.SetAttributes(“filepath”,
System.IO.FileAttributes.Normal);

 

去除文件夹的只读属性:

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

发表评论

电子邮件地址不会被公开。 必填项已用*标注