Number of files in a folder
-
What is the best way to check for a particulair file in a folder? e.g. I want to count the number of files that start with say "temp" and have an extension of txt. In this example Folder = Temp Files = temp01.txt, report.txt, temp02.txt. In this example we would return a count of 2
-
What is the best way to check for a particulair file in a folder? e.g. I want to count the number of files that start with say "temp" and have an extension of txt. In this example Folder = Temp Files = temp01.txt, report.txt, temp02.txt. In this example we would return a count of 2
Central_IT wrote:
What is the best way to ...
Depends on your definition of best. The easiest way would be based on the
Directory.GetFiles(String, String)
method, taking the Count of the array being returned. This however is not the least expensive one in terms of system load, as it is building an array of strings, which potentially could be huge and take long. The cheapest way would probably be based on calling the Win32 functionsGetFirstFile()
andGetNextFile()
, which requires P/Invoke and a bit more code. :)Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Friday, January 14, 2011 6:27 AM