在.NET去掉文件的只读属性
来源:互联网 发布:算法总结 编辑:程序博客网 时间:2024/05/16 04:17
關於 FileAttributes的所有枚舉值都在這裡:
ReadOnly = 1,
Hidden = 2,
System = 4,
Directory = 0x10,
Archive = 0x20,
Device = 0x40,
Normal = 0x80,
Temporary = 0x100
SparseFile = 0x200,
ReparsePoint = 0x400,
Compressed = 0x800,
Offline = 0x1000,
NotContentIndexed = 0x2000,
Encrypted = 0x4000,
我们可以使用 System.IO.File 类的 SetAttributes 方法为一个文件设置相关的属性,如:
// 为文件加上一个只读的属性
FileAttributes attrs = File.GetAttributes("c://a.txt");
File.SetAttributes("c://a.txt", attrs | FileAttributes.ReadOnly);
FileAttributes attrs = File.GetAttributes("c://a.txt");
File.SetAttributes("c://a.txt", attrs | FileAttributes.ReadOnly);
怎么把这个只读属性去掉呢?
// 先把文件的属性读取出来
FileAttributes attrs = File.GetAttributes("c://a.txt");
// 下面表达式中的 1 是 FileAttributes.ReadOnly 的值
// 此表达式是把 ReadOnly 所在的位改成 0,
attrs = (FileAttributes)((int)attrs & ~(1));
File.SetAttributes("c://a.txt", attrs);
FileAttributes attrs = File.GetAttributes("c://a.txt");
// 下面表达式中的 1 是 FileAttributes.ReadOnly 的值
// 此表达式是把 ReadOnly 所在的位改成 0,
attrs = (FileAttributes)((int)attrs & ~(1));
File.SetAttributes("c://a.txt", attrs);
- 在.NET去掉文件的只读属性
- 在程序中去掉EXCEL的只读属性
- 去掉文件夹和文件的只读属性
- 去掉IIS_schema.xml的只读属性
- 去掉IIS_schema.xml的只读属性
- 在VC中,如何修改文件的只读属性设置
- 如何去掉Access的只读属性之解药
- 批处理去掉所有目录的隐藏系统只读属性
- 如何去掉XP系统中文件夹的只读属性
- Python 中去除文件的只读属性
- C#中怎么样用代码去掉文件的只读
- linux文件只读属性
- [2月21日的脚本] 在Windows 8中批移除只读文件的属性 (PowerShell)
- 在VC中,如何修改文件的只读属性设置(转)
- 在VC中,如何修改文件的只读属性设置(转)
- Visual Studio 编译后去掉只读属性
- .Net/C# 实现真正的只读属性 (ReadOnly Property)
- asp.net中asp:TextBox的只读属性
- OracleERP表结构-INV模块
- dfg
- QQ空间的几张图
- 深入体验JAVA Web开发内幕——核心基础
- 自增操作符(华为面试)
- 在.NET去掉文件的只读属性
- 表哥again ——假期拾遗之一
- 张靓颖代言精油护肤产品家美乐(嘉媚乐)新造型成都开唱
- 几种C/C++的函数压栈方式
- 系统环境变量作用
- c语言关键字Volatile的使用
- 国外的黑客游戏站
- MSMQ的简单应用
- XXX管理平台系统——项目总结(over)