// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; using System.Text.RegularExpressions; namespace E { public static class MyExtensions { public static FileInfo[] GetFilesRegExp(this DirectoryInfo di, string pat) { Regex re = new Regex(pat); return Array.FindAll(di.GetFiles(), (f) => re.IsMatch(f.Name)); } } public class Program { public static void Main(string[] args) { Regex re = new Regex(@"^[Zz].*$"); DirectoryInfo di = new DirectoryInfo(@"C:\"); FileInfo[] f1 = Array.FindAll(di.GetFiles(), (f) => re.IsMatch(f.Name)); foreach(FileInfo f in f1) { Console.WriteLine(f.FullName); } FileInfo[] f2 = di.GetFilesRegExp(@"^[Zz].*$"); foreach(FileInfo f in f2) { Console.WriteLine(f.FullName); } } } }