使用:System.IO中关于File,Directory的类,
遍历整个目录,
再用: System.Xml中相关的类,生成一个Xml文件。
其中主要是遍历目录的方法实现。

解决方案 »

  1.   

    string[] dirs=System.IO.Directory.GetDirectories("F:\\");
    string[] files=System.IO.Directory.GetFiles("F:\\");
    System.Xml.XmlDocument oDoc=new System.Xml.XmlDocument();
    System.Xml.XmlNode oNode=oDoc.CreateNode(System.Xml.XmlNodeType.Element,"ROOT","");
    oDoc.AppendChild(oNode);
    System.Xml.XmlNode oChildNode=null;
    for(int i=0;i<dirs.Length;i++)
    {
    oChildNode=oDoc.CreateNode(System.Xml.XmlNodeType.Element,dirs[i].ToString().Replace("\\","").Replace(" ",""),"");
    oNode.AppendChild(oChildNode);
    }
    for(int i=0;i<files.Length;i++)
    {
    oChildNode=oDoc.CreateNode(System.Xml.XmlNodeType.Element,files[i].ToString().Replace("\\","").Replace(" ",""),"");
    oNode.AppendChild(oChildNode);
    }
    this.TextBox1.Text=oDoc.InnerXml;