using System; using System.Collections.Generic; using System.IO; using System.Linq; using Y.Utils.BaseUtils; namespace Y.Utils.FileUtils { public class FileTool { public static List GetFile(string path) { if (Directory.Exists(path)) try { return Directory.EnumerateFiles(path).ToList(); } catch (Exception e) { } return null; } public static List GetFile(string path, string ext) { if (Directory.Exists(path)) try { List result = null; List temp = Directory.EnumerateFiles(path).ToList(); if (!ListTool.IsNullOrEmpty(temp)) foreach (var item in temp) { if (Path.GetExtension(item).ToUpper() == ext.ToUpper()) { if (result == null) result = new List(); result.Add(item); } } return result; } catch (Exception e) { } return null; } public static List GetAllFile(string path) { List pathList = DirTool.GetAllPath(path); List result = GetFile(path); if (!ListTool.IsNullOrEmpty(pathList)) { foreach (var item in pathList) { List temp = GetFile(item); if (!ListTool.IsNullOrEmpty(temp)) result.AddRange(temp); } } if (!ListTool.IsNullOrEmpty(result)) return result; return null; } public static bool Delete(string file) { try { if (File.Exists(file)) { File.Delete(file); return true; } else { return true; } } catch { } return false; } public static bool Delete(string[] files) { bool result = true; if (!ListTool.IsNullOrEmpty(files)) { foreach (var file in files) { result = result || Delete(file); } } return result; } } }