示例#1
0
        public static void SearchInSubfolders(object obj)
        {
            FileWorkMain thisform = (FileWorkMain)obj;
            string       text     = thisform.tb_SearchFile.Text;

            DirectoryInfo TheFolder = new DirectoryInfo(m_strPath);

            DirectoryInfo[] Subfolders = TheFolder.GetDirectories();

            if (thisform.InvokeRequired)
            {
                RefreshFileList delegateFunc = new RefreshFileList(SearchInSubfolders);
                thisform.Invoke(delegateFunc, thisform);
            }
            else
            {
                try
                {
                    for (int i = 0; i < Subfolders.Length; i++)
                    {
                        thisform.pgb_isFinish.Value += thisform.pgb_isFinish.Step;
                        foreach (System.IO.FileInfo NextFile in Subfolders[i].GetFiles())
                        {
                            if (text != "请输入搜索内容!")
                            {
                                if (NextFile.ToString().Contains(text))
                                {
                                    ListViewItem item = new ListViewItem
                                    {
                                        Text = NextFile.FullName
                                    };
                                    item.SubItems.Add(NextFile.LastAccessTime.ToString());
                                    item.SubItems.Add(GetFileType(NextFile.Name));

                                    thisform.lvw_FileList.Items.Add(item);
                                }
                            }
                            else
                            {
                                ListViewItem item = new ListViewItem();

                                item.Text = NextFile.FullName;
                                item.SubItems.Add(NextFile.LastAccessTime.ToString());
                                item.SubItems.Add(GetFileType(NextFile.Name));

                                thisform.lvw_FileList.Items.Add(item);
                            }
                        }
                    }
                }
                catch { }
            }
        }
示例#2
0
        public static void SearchFiles(object obj)
        {
            FileWorkMain thisform = (FileWorkMain)obj;
            string       text     = thisform.tb_SearchFile.Text;

            DirectoryInfo TheFolder = new DirectoryInfo(m_strPath);

            DirectoryInfo[] Subfolders = TheFolder.GetDirectories();

            if (TheFolder.Exists)
            {
                thisform.pgb_isFinish.Value += thisform.pgb_isFinish.Step;
                try
                {
                    thisform.lvw_FileList.Items.Clear();
                    foreach (System.IO.FileInfo NextFile in TheFolder.GetFiles())
                    {
                        if (text != "请输入搜索内容!")
                        {
                            if (NextFile.ToString().Contains(text))
                            {
                                ListViewItem item = new ListViewItem();

                                item.Text = NextFile.FullName;
                                item.SubItems.Add(NextFile.LastAccessTime.ToString());
                                item.SubItems.Add(GetFileType(NextFile.Name));

                                thisform.lvw_FileList.Items.Add(item);
                            }
                        }
                        else
                        {
                            ListViewItem item = new ListViewItem
                            {
                                Text = NextFile.FullName
                            };
                            item.SubItems.Add(NextFile.LastAccessTime.ToString());
                            item.SubItems.Add(GetFileType(NextFile.Name));

                            thisform.lvw_FileList.Items.Add(item);
                        }
                    }

                    /*不建议的处理方式
                     * //SearchInSubfolders s = new SearchInSubfolders
                     * //{
                     * //    FlieList = FileList,
                     * //    text = text
                     * //};
                     * ////////Control.CheckForIllegalCrossThreadCalls = false;
                     * //Thread t = new Thread(new ThreadStart(s.Search));
                     * //t.Start();
                     */
                    Thread thread = new Thread(new ParameterizedThreadStart(SearchInSubfolders));
                    thread.Start(thisform);

                    RefreshFileList update = new RefreshFileList(SearchInSubfolders);
                    thisform.Invoke(update, thisform);
                }
                catch { }
                while (thisform.pgb_isFinish.Value < thisform.pgb_isFinish.Maximum)
                {
                    thisform.pgb_isFinish.Value += thisform.pgb_isFinish.Step;
                    //MessageBox.Show(thisform.pgb_isFinish.Value.ToString());
                }

                if (thisform.pgb_isFinish.Value == 100)
                {
                    thisform.MyDelay(600);
                    thisform.ckb_isFinish.Checked = true;
                    thisform.lbl_isFinish.Text    = "文件搜索或查询已完成";
                    //MessageBox.Show("sss");
                }
            }
            else
            {
                MessageBox.Show("文件夹不存在");
            }
        }