日期:2014-05-18  浏览次数:20718 次

C#去掉文件夹包括子目录及文件的只读属性!!
如题,有什么好方法,求分享!

------解决方案--------------------
System.IO.File.SetAttributes("c:\\1.dat", System.IO.FileAttributes.Normal)
剩下的,你就是遍历设置就行了
------解决方案--------------------
C# code

        private void SetReadOnly(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);
            }
        }