开发者

set folder read only to false

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜