怎么样通过写代码的方式让已经存在的文件夹隐藏,不管是空的或是非空的文件夹都可以!

解决方案 »

  1.   

    using System;
    using System.IO;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;public partial class getDirectory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string path = Request.QueryString["path"];        if(path == null || path == "")
                path = @"C:\Windows";               DirectoryInfo TheFolder = new DirectoryInfo(path);
            if (!TheFolder.Exists)
                throw new DirectoryNotFoundException("Folder not found: " + path);        string info = "<?xml version=\"1.0\"?><tree>";
            foreach (DirectoryInfo NextFolder in TheFolder.GetDirectories())
            {
                //判读是否是隐藏文件夹
                if(NextFolder.Attributes.ToString().IndexOf("Hidden") == -1)
                    info += "<tree text=\"" + NextFolder.Name + "\" src=\"" + NextFolder.FullName + "\"/>";
            }        info += "</tree>";
            Response.Clear();
            Response.ContentType="text/xml";
            Response.Charset="UTF-8";
            Response.Write(info);
            Response.End();
        }
    }
    借用别人的,注意搜索啊,哥们
      

  2.   

    一般性的隐藏可以使用SetFileAttributes("路径", FILE_ATTRIBUTE_HIDDEN);   
    如果想要达到通过“显示隐藏文件”都看不到的话则要写文件驱动了.
      

  3.   

    File.SetAttributes("c:\\123", FileAttributes.Hidden);
      

  4.   


    DirectoryInfo dirInfo = new DirectoryInfo(path);
    dirInfo.Attributes = dirInfo.Attributes | FileAttributes.Hidden;