public string[] List(FilenameFilter filter) { try { if (IsFile()) { return(null); } List <string> list = new List <string> (); foreach (string filePth in Directory.GetFileSystemEntries(path)) { string fileName = Path.GetFileName(filePth); if ((filter == null) || filter.Accept(this, fileName)) { list.Add(fileName); } } return(list.ToArray()); } catch { return(null); } }
/// <summary> /// Return the complete list of files in a directory as strings.<p/> /// This is better than File#listDir because it does not ignore IOExceptions. /// </summary> /// <param name="dir">The directory to list.</param> /// <param name="filter"> /// If non-null, the filter to use when listing /// this directory. /// </param> /// <returns>The list of files in the directory.</returns> /// <exception cref="System.IO.IOException">On I/O error</exception> public static IList <string> ListDirectory(FilePath dir, FilenameFilter filter) { AList <string> list = new AList <string>(); try { using (DirectoryStream <Path> stream = Files.NewDirectoryStream(dir.ToPath())) { foreach (Path entry in stream) { string fileName = entry.GetFileName().ToString(); if ((filter == null) || filter.Accept(dir, fileName)) { list.AddItem(fileName); } } } } catch (DirectoryIteratorException e) { throw ((IOException)e.InnerException); } return(list); }
private IList <FilePath> FindAllFiles(FilePath top, FilenameFilter mask) { if (top == null) { return(null); } AList <FilePath> ret = new AList <FilePath>(); foreach (FilePath f in top.ListFiles()) { if (f.IsDirectory()) { Sharpen.Collections.AddAll(ret, FindAllFiles(f, mask)); } else { if (mask.Accept(f, f.GetName())) { ret.AddItem(f); } } } return(ret); }
public string[] List (FilenameFilter filter) { try { if (IsFile ()) return null; List<string> list = new List<string> (); foreach (string filePth in Directory.GetFileSystemEntries (path)) { string fileName = Path.GetFileName (filePth); if ((filter == null) || filter.Accept (this, fileName)) { list.Add (fileName); } } return list.ToArray (); } catch { return null; } }