如何更改为使用C#的文件夹中的每个文件的只读文件属性? [英] How do I change the Read-only file attribute for each file in a folder using c#?

查看:257
本文介绍了如何更改为使用C#的文件夹中的每个文件的只读文件属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用C#更改每个文件的只读文件属性的文件夹中?



感谢


解决方案

 的foreach(在System.IO.Directory.GetFiles字符串文件名(路径))
{
System.IO .FileInfo的fileInfo =新System.IO.FileInfo(文件名);

fileInfo.Attributes | = System.IO.FileAttributes.ReadOnly;
//或
fileInfo.IsReadOnly = TRUE;
}


How do I change the Read-only file attribute for each file in a folder using c#?

Thanks

解决方案

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;
}

这篇关于如何更改为使用C#的文件夹中的每个文件的只读文件属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆