我想做 一个读取指定路径下的同一类型的文件
比如  的D:\\test 下面 所有的txt文件 的内容
把同一类型文件的内容 用二进制显示出来
我的界面是:
我的代码是:
namespace 路径读取
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }        private void btnWhere_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog path = new FolderBrowserDialog();
            path.ShowDialog();
            this.road.Text = path.SelectedPath;
        }        private void btnBegin_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(Find);
            thread.Start();
        }
        public void Find()
        {
            while (true)
            {
                Thread.Sleep(1000);
            }
        }
    }
}新手 多谅解!跪谢!!!
我想 点击Begin之后  循环一直在读取路径下的某种类型的文件。
用MessageBox显示出来 就行
新手 理解上有些困难...  希望 稍微附上代码  解释一下
新手跪谢!!!

解决方案 »

  1.   

    读取指定后缀名的文件,不支持遍历,你可以用递归实现。
    StringBuilder sb = new StringBuilder();
                string[] files = Directory.GetFiles("xxx", "*.txt");//xxx为path
                foreach (string item in files)
                {
                    sb.Append(item + "\r\n");
                }
                MessageBox.Show(sb.ToString());
      

  2.   

    sorry,加上这句就支持遍历了。
      string[] files = Directory.GetFiles("xxx", "*.txt", SearchOption.AllDirectories);//xxx为path
      

  3.   

    foreach (string FileName in Directory.GetFiles("D:\\", "*.txt"))
                {
                    string btysStr = string.Empty;
                    foreach (byte bty in File.ReadAllBytes(FileName))
                        btysStr += Convert.ToString(bty, 2).PadLeft(8, '0') + " ";
                    MessageBox.Show(btysStr, FileName);
                }
      

  4.   

    string ty = "*.xls";
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                if (fbd.ShowDialog() == DialogResult.OK)
                {
                    System.IO.FileInfo[] list = System.IO.Directory.CreateDirectory(fbd.SelectedPath).GetFiles(ty);
                    StringBuilder sb = new StringBuilder();
                    foreach (System.IO.FileInfo f in list)
                    {
                        sb.Append(f.FullName.ToString() + "    ");
                    }
                    MessageBox.Show(sb.ToString());
                }