
本文共 5014 字,大约阅读时间需要 16 分钟。
/**** Title���"���������" ������ */ /**** Theme������������������������������������������������ */ /**** Description��������������� */ /**** Date���2019��� */ /**** Version���0.1������ */ /**** Author���Coffee */ /**** Modifier��� */using System; using System.Collections.Generic; using System.IO; namespace kernal { public class GetAllFileOfFolder { private static readonly List_FileList = new List (); private GetAllFileOfFolder() { // ��������������������������� _FileList = new List (); } #regionozillaModal public static List GetAllFile(string path, string extName) { if (string.IsNullOrWhiteSpace(path)) { if (Directory.Exists(path)) { GetAllFilesOfDirectory(path, extName); } else { Directory.CreateDirectory(path); if (Directory.Exists(path)) { GetAllFilesOfDirectory(path, extName); } } } else { // ��������������������������������� EverydayLog.Write("GetAllFileOfFolder/GetallFile()/������������������������������������������������������"); } return _FileList; } #endregion #region private static void GetAllFilesOfDirectory(string path, string extName) { try { DirectoryInfo directory = new DirectoryInfo(path); if (directory.Exists) { FileInfo[] files = directory.GetFiles(); if (files.Length > 0) { foreach (FileInfo file in files) { if (IsMatchExtension(extName, file.Extension)) { _FileList.Add(file); } } foreach (string subDirectory in directory.GetDirectories()) { GetAllFilesOfDirectory(subDirectory, extName); } } } } catch (Exception ex) { EverydayLog.Write("GetAllFileOfFolder/GetallfilesOfDir()/���������������������" + path + " ������������������������������������������=" + ex.Message); } } private static bool IsMatchExtension(string targetExt, string currentExt) { if (string.IsNullOrEmpty(targetExt) || string.IsNullOrEmpty(currentExt)) { return false; } return string.Equals(currentExt, targetExt, StringComparison.OrdinalIgnoreCase); } } } ������������������������
���������������������������������������������������������������������������������������������������������
���������������������������
1. GetAllFile(string path, string extName) ���������������������������������������
2. GetAllFilesOfDirectory(string path, string extName) ������������������������������������������������������
3. IsMatchExtension(string targetExt, string currentExt) ���������������������������������������������������
���������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
