想实现
选定指定文件夹
点击按钮
在richtextbox不断地刷新显示该文件夹每个一个文件路径的字符我猜想要用到多线程,但是我没办法实现显示字符的动态变化效果
本人菜鸟,请高手赐点代码,不胜感激。

解决方案 »

  1.   

    批处理:For /r c:\ %i in (.) do echo   %i- -
    先判断是否为目录,然后返回路径名,然后显示在Label上
    GetFiles方法:  返回指定目录中的文件的名称。  
    GetFileSystemEntries方法:  返回指定目录中所有文件和子目录的名称。 
      

  2.   

    文件的效果,对不起
    to wiki14我做不出效果来,我知道怎么显示
      

  3.   

    不要用richtextbox,用label不停改变其Text值即可...非要用richtextbox每次都要先清空其Text...
      

  4.   

    新建winform,添加两个lable,一个buttonpublic partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                label2.Text = "";
            }        private void button1_Click(object sender, EventArgs e)
            {
                new Thread(new ThreadStart(this.Scan)).Start();
            }
            private void Scan()
            {
                ScanFile("E:\\");
            }
            private void ScanFile(string Dir)
            {
                string Filepath = "";
                try
                {
                    String[] CDirs = Directory.GetDirectories(Dir);
                    if (CDirs.Length > 0)
                    {
                        for (int i = 0; i < CDirs.Length; i++)
                        {
                            ScanFile(CDirs[i]);
                        }
                    }
                    String[] CFiles = Directory.GetFiles(Dir);
                    if (CFiles.Length > 0)
                    {
                        for (int j = 0; j < CFiles.Length; j++)
                        {
                            Filepath = Dir + @"\" + CFiles[j];
                            Invoke(new ShwMessage(ShowMessage), new object[] { Filepath });
                        }
                    }
                }
                catch
                {
                }
              
            }
            private void ShowMessage(string _Text)
            {
                label2.Text = _Text;
            }
            
            private delegate void ShwMessage(string _Text); 
        }
      

  5.   

    把遍历文件夹的代码放到线程里.然后改写设置richtextbox的代码为:
    this.Invoke (new Action ()=> richtextbox.AppendText (文件路径+"\n"));应该就行了.不过遍历的速度会变得慢下来.
      

  6.   

    TO
    ChrisAK
    不管是一行一行逐步显示,还是直接在原来上面的的替换,都可以
    要是一个看是在动,在扫描的效果
    多线程我不是很精通,我试了试没成功,百度google都找过了,没有答案,所以来求助了望各位大大,不吝赐教
      

  7.   


    ...using System;
    using System.IO;
    using System.Windows.Forms;
    using System.Threading;class showfiles:Form
    {
        RichTextBox rt_file = new RichTextBox();
        showfiles()
        {
            Controls.Add(rt_file);
            rt_file.Dock = DockStyle.Fill;
        }
        void getfiles(string dir)
        {
            string[] files;
            string[] subdirs;
            try{
                files = Directory.GetFiles(dir);
                subdirs = Directory.GetDirectories(dir);
            }catch(Exception){
                return;
            }
            foreach (var file in files)
                Invoke(new Action(() => rt_file.Text = file));
            foreach (var subdir in subdirs)
                getfiles(subdir);    }
        protected override void OnShown(EventArgs e)
        {
            new Thread(new ThreadStart(() => getfiles("c:\\"))).Start();
        }
        static void Main()
        {
            new showfiles().ShowDialog();
        }
    }存成cs文件后直接在vs的命令提示符下用csc编译.
      

  8.   

    如果lz用的是Windform:一句话
    在循环中加入
     System.Windows.Forms.Application.DoEvents();
    就可以了。扫描文件出现文件的文件路径,我做的对象生成器也是用这个显示文件生成的地址
      

  9.   

    如果lz用的是Windform:一句话
    在循环中加入
     System.Windows.Forms.Application.DoEvents();
    就可以了。扫描文件出现文件的文件路径,我做的对象生成器也是用这个显示文件生成的地址