示例#1
0
        private void updateListBox(object sender)
        {
            if (this.InvokeRequired)
            {
                RefreshFileListBoxHanlder delegateFunc = new RefreshFileListBoxHanlder(updateListBox);
                this.Invoke(delegateFunc, sender);
            }
            else
            {
                if (listVwFilelist.Items.Count > 0)
                {
                    listVwFilelist.Items.Clear();
                }
                foreach (string file in searchedFiles)
                {
                    FileInfo CurrentFile = new FileInfo(file);
                    string   fileType    = Path.GetExtension(CurrentFile.Name);

                    //加入文件进list
                    ListViewItem item = new ListViewItem(file);
                    item.SubItems.Add(fileType);
                    item.SubItems.Add(CurrentFile.Name);
                    item.SubItems.Add(CurrentFile.LastWriteTime.ToString());
                    this.listVwFilelist.Items.Add(item);
                }
            }
        }
示例#2
0
        //
        //功能函数模块
        //

        private void GetFile(object obj)
        {
            MainForm thisForm = (MainForm)obj;
            string   strDir   = this.tboxFilePath.Text;

            if (strDir != null && strDir.Length > 0)
            {
                if (Directory.Exists(strDir))
                {
                    //定义文件夹队列
                    List <string> queueFolder     = new List <string>();
                    List <string> allSearcheFiles = new List <string>();

                    //加入当前文件夹路径
                    queueFolder.Add(strDir);
                    while (queueFolder.Count > 0)
                    {
                        try
                        {
                            //获取队列头文件夹路径
                            string curFolder = queueFolder[0];

                            //移除队列
                            queueFolder.RemoveAt(0);

                            //获取当前路径的所有文件
                            string[] files = Directory.GetFiles(curFolder);
                            //获取当前路径文件夹
                            string[] dirs = Directory.GetDirectories(curFolder);
                            //将所有文件加入
                            foreach (string item in files)
                            {
                                allSearcheFiles.Add(item);
                            }
                            //将当前路径的文件夹路径加入队列
                            foreach (string item in dirs)
                            {
                                queueFolder.Add(item);
                            }
                        }
                        catch { }
                    }
                    searchedFiles.AddRange(allSearcheFiles);

                    RefreshFileListBoxHanlder updateDelegate = new RefreshFileListBoxHanlder(thisForm.updateListBox);
                    thisForm.Invoke(updateDelegate, thisForm);
                }
            }
        }
示例#3
0
 public MainForm()
 {
     InitializeComponent();
     searchedFiles   = new List <string>();
     searchComplete += new RefreshFileListBoxHanlder(updateListBox);
 }