.net - Find files with matching patterns in a directory c#? -
string filename = ""; string sourcepath = @"c:\vish"; string targetpath = @"c:\sr"; string sourcefile = system.io.path.combine(sourcepath, filename); string destfile = system.io.path.combine(targetpath, filename); string pattern = @"23456780"; var matches = directory.getfiles(@"c:\vish") .where(path => regex.match(path, pattern).success); foreach (string file in matches) { console.writeline(file); filename = system.io.path.getfilename(file); console.writeline(filename); destfile = system.io.path.combine(targetpath, filename); system.io.file.copy(file, destfile, true); } my above program works single pattern.
i'm using above program find files in directory matching pattern in case i've multiple patterns need pass multiple pattern in string pattern variable array don't have idea how can manipulate pattern in regex.match.
can me?
you can put or in regex :
string pattern = @"(23456780|otherpatt)";
Comments
Post a Comment