c# - Exclude results from Directory.GetFiles -



c# - Exclude results from Directory.GetFiles -

if want phone call directory.getfiles , have homecoming files match pattern *.bin want exclude of files match pattern log#.bin # running counter of indeterminate length. there way filter out results @ step of passing in search filter getfiles or must result array remove items want exclude?

you can utilize linq, directory.enumeratefiles() , where() filter - way end files want, rest filtered out.

something should work:

regex re = new regex(@"^log\d+.bin$"); var logfiles = directory.enumeratefiles(somepath, "*.bin") .where(f => !re.ismatch(path.getfilename(f))) .tolist();

as pointed out directory.enumeratefiles requires .net 4.0. cleaner solution (at cost of little more overhead) using directoryinfo / enumeratefiles() returns ienumerable<fileinfo> have direct access file name , extension without farther parsing.

c# .net

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -