怎样去除文件夹的只读属性

taozeng 2004-05-14 02:29:53
我想做拷贝文件的程序。但是发现如果文件是只读的,拷贝同名文件,并不能覆盖旧文件。所以想通过程序去掉该目录的只读属性。希望高手给予指点。
...全文
1615 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
taosihai1only 2004-05-14
  • 打赏
  • 举报
回复
DirectoryInfo mDir=new DirectoryInfo("C:\\test");
mDir.Attributes=FileAttributes.Normal;
System.IO.File.SetAttributes(file, System.IO.FileAttributes.Normal);

自己看一下书完全可以搞定
milkbb 2004-05-14
  • 打赏
  • 举报
回复
这么多人都说完了。
vzxq 2004-05-14
  • 打赏
  • 举报
回复
学习。
lwjlwj 2004-05-14
  • 打赏
  • 举报
回复
System.IO.File.SetAttributes(filePath, System.IO.FileAttributes.Normal);
eTopFancy 2004-05-14
  • 打赏
  • 举报
回复
FileAttributes atr = File.GetAttributes(strFileName);
//如果属性中包含只读性
if(atr == (atr|FileAttributes.ReadOnly))
{
try
{
//去除文件只读性
atr = atr&(~FileAttributes.ReadOnly);
File.SetAttributes(ParamsFileName,atr);
}
catch(System.Exception err)
{
MessageBox.Show(this,err.Message,"保存数据库配置",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return;
}
lxcc 2004-05-14
  • 打赏
  • 举报
回复
up
daguzhang 2004-05-14
  • 打赏
  • 举报
回复
System.IO.File.SetAttributes(filePath, System.IO.FileAttributes.Normal);
jackie615 2004-05-14
  • 打赏
  • 举报
回复
都可以

UP
CMIC 2004-05-14
  • 打赏
  • 举报
回复
using System.IO;

DirectoryInfo mDir=new DirectoryInfo("C:\\test");
mDir.Attributes=FileAttributes.Normal;
linaren 2004-05-14
  • 打赏
  • 举报
回复
File.SetAttributes(fpath, File.GetAttributes(fpath) | FileAttributes.Normal);
idiotzeng 2004-05-14
  • 打赏
  • 举报
回复
System.IO.File.SetAttributes(file, System.IO.FileAttributes.Normal);

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧