There is no such thing as miracle. If you have some value of MD5, you will need to read each file at least once, all its content, calculate MD5 of the data and compare with your MD5 value. It will take time.
There is nothing you can bypass. If you have some silliness in your code, you have to eliminate it, of course, but… Oh, wait a minute, you have one: you are wasting time on considering all the files, not just "*.exe" and calculating
EndsWith
. You should use file mask instead:
http://msdn.microsoft.com/en-us/library/ms143316%28v=vs.110%29.aspx[
^].
However, you need to know one Microsoft problem related to it, described here:
Directory.Get.Files search pattern problem[
^].
You will save some time on it, but I think this optimization would be minor compared to the time needed to read file and calculate MD5.
—SA