开发者

set folder read only to false

开发者 https://www.devze.com 2023-03-11 23:08 出处:网络
Currently my code to set the folder read only to false. var di = new DirectoryInfo(\"C:\\\\NightlyBuild\");

Currently my code to set the folder read only to false.

var di = new DirectoryInfo("C:\\NightlyBuild");
            foreach (var file in di.GetFiles("*", SearchOption.AllDirectories))
                file.Attributes &= ~FileAttributes.ReadOnly;

However, I did this to find the file in smallest file by sorting them in decesending order:

string path = "C:\\NightlyBuild\\";
var files = Directory.GetDirectories(path, "NightlyBuild.*");
            foreach(var file in files)
            Console.WriteLine(file);
            foreach(var file in files.OrderByDescending(x=>x).Skip(int.Parse(args[0])))
            Console.WriteLine(file);
            foreach(var file in files.OrderByDescending(x=>x).Skip(int.Parse(args[0])))
            Directory.Delete(file, true);

Any way to alter this code so that whatever file that i delete?

I just开发者_如何学Go want to set that file read-only to false? This file is actually a folder fyi


Try

File.SetAttributes("C:\\NightlyBuild", FileAttributes.ReadOnly);
0

精彩评论

暂无评论...
验证码 换一张
取 消