修改文件属性

Posted on 2019-01-04 21:31  努力成长静待花开  阅读(387)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  FileInfo类的Attribute属性    //获取或设置文件的属性

  public FileAttributes Attributes {get; set;}

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
           System.IO.FileInfo file=new System.IO.FileInfo(textBox1.Text);
            if (checkBox1.Checked == true) {
                file.Attributes = System.IO.FileAttributes.ReadOnly;
            }else if (checkBox2.Checked == true){
                file.Attributes = System.IO.FileAttributes.System;
            }else if (checkBox3.Checked == true){
                file.Attributes = System.IO.FileAttributes.Archive;
            }else if (checkBox4.Checked == true){
                file.Attributes = System.IO.FileAttributes.Hidden;
            }
        }