随笔-28  评论-17  文章-1  trackbacks-5

我们可以使用 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");

// 下面表达式中的 1 是 FileAttributes.ReadOnly 的值
   // 此表达式是把 ReadOnly 所在的位改成 0,
attrs = (FileAttributes)((int)attrs & ~(1));

File.SetAttributes(
"c:\\a.txt", attrs);

posted on 2004-12-24 18:54 匡匡 阅读(2149) 评论(3)  编辑 收藏 所属分类: ASP.NET

评论:
#1楼  2004-12-25 20:05 | 柚子男      
關於 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,

  回复  引用  查看    
#2楼  2005-11-03 10:25 | qmttz [未注册用户]
我看不懂啊,请大虾写详细点。我的 邮箱是istjt0@163.com
  回复  引用    
#3楼  2006-02-27 23:36 | 唐凌波永州的 [未注册用户]
湖南永州的,一个穷地方,我学这个很久了,但我还是看不懂,我的qq:254460003
我的邮箱是lomal@163.com 蚂蚁团结起来,可以摧毁世界.
 你的回复,是我的动力.
  回复  引用    

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
该文被作者在 2004-12-26 14:12 编辑过
"五向定位"职业成长路线公开课(上海、南京、大连)
Google站内搜索


相关链接: