Download SD Library V4.1.5
Original forum post can be found here.

Written by Michael Lebert

NOTE: An updated version of this library (v4.1.6) is now included as part of the standard libraries in v2.2.3.0


I noticed that the DIR command to search for all files in a directory becomes extremely slow when large numbers of files are encountered. For example, with a little over 1000 files it could take a couple of minutes to complete. The modifications made to the library reduces this time to only a few seconds. I have also modified the routine that returns the size of a file without the requirement to open the file first.