示例#1
0
        private void txtFindAll_Click(object sender, EventArgs e)
        {
            try
            {
                Regex reg = new Regex(txtReg.Text, RegexOptions.Multiline);
                EasyDirectory di = new EasyDirectory(txtSourceDirectory.Text);

                if (reg == null)
                {
                    throw new Exception("正则表达式错误");
                }

                if (di == null)
                {
                    throw new Exception("源文件夹路径错误");
                }
                List<FileInfo> files = di.GetFiles(true);
                List<string> matchString = FindFromFiles(reg, files.ToArray());                
                FindResult(matchString);
            }
            catch (Exception ex)
            {
                OutputResult("查询时出错:", OutputMode.Set);
                OutputResult(ex.ToString(), OutputMode.Append);
            }
        }
示例#2
0
        /// <summary>
        /// 获取文件夹内的文件集合
        /// Steven Weng 2014-09-16
        /// </summary>
        /// <param name="recursive">是否递归获取子文件夹中的文件</param>
        /// <returns></returns>
        public List<FileInfo> GetFiles(bool recursive)
        {
            List<FileInfo> files = new List<FileInfo>();
            files.AddRange(directory.GetFiles());

            if (recursive)
            {
                EasyDirectory currentSubDirectory = null;
                DirectoryInfo[] direcotries = directory.GetDirectories();
                if (direcotries != null)
                {
                    foreach (DirectoryInfo di in direcotries)
                    {
                        currentSubDirectory = new EasyDirectory(di);
                        files.AddRange(currentSubDirectory.GetFiles(recursive));
                    }
                }
            }
            return files;
        }