公司有个小项目,其中需要用到建立 一个隐藏的文件目录,再往其中写入一些信息文件.
  本人从未涉及过,不过找了一些资料,只找到了简单的隐藏或者是改写文件属性为系统文件,
  觉得太简单了,大家有没有更复杂一点的,是隐藏啊,不要加密...文件才加密...

解决方案 »

  1.   


    你如果为了保护文件夹,可以隐藏,也可以伪装文件夹
    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是一个文件夹
      

  2.   

    创建文件后,用FileInfo.Attributes修改文件的属性。FileAttributes.Hidden表示隐藏
      

  3.   

    说错了,要用DirectoryInfo 类来设置目录的属性!
    DirectoryInfo.Attributes=FileAttributes.Hidden
      

  4.   

    to q107770540:感谢你肯帮我上百度搜索,但请不要复制代码。
    to hanxuetaotao1:我问隐藏呢,不是说存放.
    to computerfox:你好,设置目录隐藏以后无论如何都看不到了吗?还是说还是可以看到的?,这种隐藏方法的本质是什么?可以谈谈吗?
      

  5.   

    就是FileAttributes.Hidden啊 还是没明白你的意思
      

  6.   

    to hitlcyu19: 感谢你的回答,我是问FileAttributes.hidden 或 DirectoryInfo.hidden之后,无论如何看不到了吗?如果是的,我想问这种实现隐藏的本质或者原理是怎样 的啊
      

  7.   

    把文件夹的属性改了一下吧:
      FileAttributes.Hidden 这样就隐藏了
      

  8.   

    FileAttributes.Hidden 隐藏前提是 系统的 文件夹选项-查看-不显示隐藏的文件你如果想在 文件夹选项-查看-显示隐藏的文件 时仍然隐藏文件夹那就难了
      

  9.   

    FileAttributes.Hidden 让我失望了,我刚做了小程序,这个只是简单的修改文件属性,正如楼上所说,但是这根本就不是真正的隐藏,只是个系统文件而已,随便设置一下也出来了。大家还有其他办法吗?
      

  10.   

    to q107770540:关键是这段代码我也搜索到过,不过还是感激你,最主要的原因是这段代码根本不能解决问题呢,FileAttributes 最多也就做到 dos命令  attrib做到的吧?但是明显还是不能真正隐藏.
      

  11.   

                string Dir = "d:\\123";            if (!Directory.Exists(Dir))
                {
                    Directory.CreateDirectory(Dir);
                }            DirectoryInfo di = new DirectoryInfo(Dir);
                di.Attributes = di.Attributes | FileAttributes.Hidden;
      

  12.   

    to spmzfz: 这个也只是简单的隐藏罢了,把查看隐藏文件的勾勾上即可出来,没有多大的用处啊.
      

  13.   

    几年前做过,具体的忘了,通过修改注册表建立桌面命名空间来实现系统级隐藏.具体可以参考注册表中NameSapce分支下的内容,现如今有些恶意软件建立的桌面无法删除的图标就是通过这种方式.