如何使用c#更改文件夹中每个文件的只读文件属性?
谢谢
foreach (string fileName in System.IO.Directory.GetFiles(path)) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName); fileInfo.Attributes |= System.IO.FileAttributes.ReadOnly; // or fileInfo.IsReadOnly = true; }
你可以试试这个:迭代每个文件和子目录:
public void Recurse(DirectoryInfo directory) { foreach (FileInfo fi in directory.GetFiles()) { fi.IsReadOnly = false; // or true } foreach (DirectoryInfo subdir in directory.GetDirectories()) { Recurse(subdir); } }