C#创建隐藏文件

【shinaterry】:
用FileInfo类可以实现...

【crescens】:
是说把属性改为隐藏吗?这太简单了

我觉得不是这个意思

【cq_lqj】:
你如果为了保护文件夹,可以隐藏,也可以伪装文件夹
private void button3_Click(object sender, EventArgs e)
{
    File.SetAttributes(textBox1.Text, FileAttributes.Normal);//设置文件夹属性为正常
    Directory.SetCreationTime(textBox1.Text, dateTimePicker1.Value);//设置文件夹创建时间
    Directory.SetLastWriteTime(textBox1.Text, dateTimePicker2.Value);//设置文件夹最近被修改时间
    Directory.SetLastAccessTime(textBox1.Text, dateTimePicker3.Value);//设置文件夹最近被访问时间
    if (checkBox1.Checked == true)
        File.SetAttributes(textBox1.Text, FileAttributes.ReadOnly);//设置成只读文件夹
    FileAttributes MyAttributes = File.GetAttributes(textBox1.Text);
    if (this.checkBox2.Checked == true)
        File.SetAttributes(textBox1.Text, MyAttributes | FileAttributes.System);//设置添加系统文件夹
    MyAttributes = File.GetAttributes(textBox1.Text);
    if (this.checkBox3.Checked == true)
        File.SetAttributes(textBox1.Text, MyAttributes | FileAttributes.Hidden);//设置添加隐藏文件夹
    MyAttributes = File.GetAttributes(textBox1.Text);
    if (this.checkBox4.Checked == true)
        File.SetAttributes(textBox1.Text, MyAttributes | FileAttributes.Archive);//设置添加归档文件夹
    MyAttributes = File.GetAttributes(textBox1.Text);
    MessageBox.Show("设置文件夹属性操作成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

注:textBox1.Text是一个文件夹

立即成为编程经验丰富的程序员不是梦,详见:http://www.psec.net.cn

【yooyooming】:
thanks
 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值