C#递归遍历文件夹下的文件

        /// <summary>
        /// 递归搜索文件夹下的文件 
        /// </summary>
        /// <param name="dir">文件夹路径</param>
        private void GetAll(DirectoryInfo dir)
        {
            FileInfo[] allFile = dir.GetFiles();
            foreach (FileInfo fi in allFile)
            {
                if (Path.GetExtension(fi.Name) == ".xls")//遍历文件后缀为.xls的文件
                {
                    FindWord(fi.FullName);
                }
            }
            DirectoryInfo[] allDir = dir.GetDirectories();
            foreach (DirectoryInfo d in allDir)
            {
                GetAll(d);
            }
        }

posted @ 2013-04-17 18:02  Johan-Choi  阅读(239)  评论(0编辑  收藏  举报