菜鸟求教
请问大家,怎么用XML配置文件遍历我的电脑,在窗体里把里面的文件夹显示出来?
谢谢

解决方案 »

  1.   

    这个根本用不上XML文件就是简单的IO操作,你在工程中引入System.IO空间,就可以了 
      

  2.   

    写了个简单的读取文件,及其子文件的方法,分拿来,不懂你再问我。
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                CreateParent();
            }        void CreateParent()
            {
                string path="";//这里写路径,读取的文件是这个路径下的所有文件,包括子文件
                TreeNode parent = new TreeNode();
                parent.Text = path;
                tvType.Nodes.Add(parent);
                CreateChild(path,parent);
            }
            void CreateChild(string path, TreeNode parent)
            {
                DirectoryInfo di = new DirectoryInfo(path);
                DirectoryInfo[] arrs = di.GetDirectories();
                foreach(DirectoryInfo arr in arrs)
                {
                    TreeNode child = new TreeNode();
                    child.Text = arr.Name;
                    child.Tag = arr.FullName;
                    parent.Nodes.Add(child);
                    CreateFile(arr.FullName, child);
                }
            }
            void CreateFile(string path, TreeNode child)
            {
                DirectoryInfo files = new DirectoryInfo(path);
                FileInfo[] fis = files.GetFiles();
                foreach (FileInfo fi in fis)
                {
                    TreeNode f = new TreeNode();
                    f.Text = fi.Name;
                    f.Tag = fi.FullName;
                    child.Nodes.Add(f);
                }
            }
      

  3.   

    xml是文件格式,一个抽象的名词。遍历是动词。如果xml可以遍历我的电脑,你还不如用科学发展观来遍历下你的大脑。