removing readonly from folder, its sub folders and all the files in it

前端 未结 3 1393
星月不相逢
星月不相逢 2021-01-22 02:56

is there a way that i can remove the property \"read only\"?

i tried this:

var di = new DirectoryInfo(\"C:\\\\Work\");
                di.Attributes &         


        
3条回答
  •  离开以前
    2021-01-22 03:18

    A better way of doing might be.

    string cmd = string.Format(" /C ATTRIB -R  \"{0}\\*.*\" /S /D", binPath);
    CallCommandlineApp("cmd.exe", cmd);
    
    private static bool CallCommandlineApp(string progPath, string arguments)
    {
       var info = new ProcessStartInfo()
        {
            UseShellExecute = false,
            RedirectStandardOutput = true,
            FileName = progPath,
            Arguments = arguments
    
        };
    
        var proc = new Process()
        {
            StartInfo = info
        };
        proc.Start();
    
        using (StreamReader stReader = proc.StandardOutput)
        {
            string output = stReader.ReadToEnd();
            Console.WriteLine(output);
    
        }
    
        // TODO: Do something with standard error. 
        proc.WaitForExit();
        return (proc.ExitCode == 0) ? true : false;
    }
    

    I ran into this samiliar problem of wanting to clear the read/write flag of a directory and any sub-files/directories it might have. And using a foreach loop sound like extra work, when the Attrib command line function works just fine and is almost instantaneous.

提交回复
热议问题