K Viltersten wrote:
I'll be working with regular expressions and
hopeful as i am, i count on that there are
tools ready to handle e.g. file operations
using regular expressions.
Please tell me it's so and give me a pointer
to what classes/packages to aim at.
For inspiration see below.
Arne
=============== =============== ========
using System;
using System.IO;
using System.Text.Reg ularExpressions ;
namespace E
{
public static class MyExtensions
{
public static FileInfo[] GetFilesRegExp( this DirectoryInfo di,
string pat)
{
Regex re = new Regex(pat);
return Array.FindAll(d i.GetFiles(), (f) =>
re.IsMatch(f.Na me));
}
}
public class Program
{
public static void Main(string[] args)
{
Regex re = new Regex(@"^[Zz].*$");
DirectoryInfo di = new DirectoryInfo(@ "C:\");
FileInfo[] f1 = Array.FindAll(d i.GetFiles(), (f) =>
re.IsMatch(f.Na me));
foreach(FileInf o f in f1)
{
Console.WriteLi ne(f.FullName);
}
FileInfo[] f2 = di.GetFilesRegE xp(@"^[Zz].*$");
foreach(FileInf o f in f2)
{
Console.WriteLi ne(f.FullName);
}
Console.ReadKey ();
}
}
}