From 00287ae4817f25b9986b2f70f6dfed19cd98112d Mon Sep 17 00:00:00 2001 From: lhiven Date: Wed, 27 Nov 2024 10:11:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E7=9A=84=E5=8F=AA=E8=AF=BB=E5=B1=9E=E6=80=A7=E7=9A=84=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rs.Framework/DirectoryHelper.cs | 54 ++++++++++++++++++++++++++++++++ Rs.Framework/Rs.Framework.csproj | 1 + 2 files changed, 55 insertions(+) create mode 100644 Rs.Framework/DirectoryHelper.cs diff --git a/Rs.Framework/DirectoryHelper.cs b/Rs.Framework/DirectoryHelper.cs new file mode 100644 index 0000000..98d3997 --- /dev/null +++ b/Rs.Framework/DirectoryHelper.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Rs.Framework +{ + public static class DirectoryHelper + { + /// + /// 移动文件夹的只读属性 + /// + /// 文件夹路径 + /// 是否包含文件 + /// 是否包含子文件夹 + public static void RemoveReadOnlyAttribute(string dirPath,bool containFile=false,bool recursive=false) + { + if (!string.IsNullOrEmpty(dirPath)) + { + DirectoryInfo di = new DirectoryInfo(dirPath); + if(di!=null) + { + di.Attributes = FileAttributes.Normal & FileAttributes.Directory; + if (containFile) + { + //查找所有的文件 + string[] files = Directory.GetFiles(dirPath); + if (files != null && files.Length > 0) + { + foreach (string f in files) + { + File.SetAttributes(f, FileAttributes.Normal); + } + } + } + if (recursive) + { + //查找所有的文件夹 + string[] dirs = Directory.GetDirectories(dirPath); + if (dirs != null && dirs.Length > 0) + { + foreach (string d in dirs) + { + RemoveReadOnlyAttribute(d); + } + } + } + } + } + } + } +} diff --git a/Rs.Framework/Rs.Framework.csproj b/Rs.Framework/Rs.Framework.csproj index 92cdea0..e666ff7 100644 --- a/Rs.Framework/Rs.Framework.csproj +++ b/Rs.Framework/Rs.Framework.csproj @@ -58,6 +58,7 @@ +