c# - Fastest call to count matching files in a Windows directory? -


trying count of files folder matching given mask, want avoid expense of returning each match or list, since there potentially tens of thousands of matches.

i findnextfile repeatedly until done, that's lot of costly round trips.

is there convenience function this?

this code in use now, , since need count, looking less-costly way there:

string[] files = system.io.directory.getfiles(path, infilemask); if (files.length == expectedcount) 

you should able achieve using microsoft indexing service. there's another article here. unfortunately, not active on every system , not reliable.

a better option implement own indexing service. can scan whole pc when app started, , rely on filesystemwatcher listen file changes on system. way can implement fast file enumeration , able return file counts in less microseconds.

an easier approach use excellent faster directory enumeration tool has mask/filter support can handle this. e.g.

var filescount = fastdirectoryenumerator.getfiles(path, infilemask).length; 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -