I
I
Ivan2021-09-08 17:30:18
C++ / C#
Ivan, 2021-09-08 17:30:18

How to iterate over a large array of files?

Good afternoon.
Technologies : C# , .net 4.7. (There is no .net core and there is no way to add it).
A large array of files on the disk (tens of thousands), you need to open each file (third-party software is not the point), read the data, close it. Plus, files must be filtered by extension. There is only one root directory.
Directory.GetFiles cannot be used because a huge array will consume a lot of memory.
I understand you need something like that. , i.e. use Win API calls.
m.b. is there a better solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2021-09-08
@Iv_and_S

As already mentioned, Directory.EnumerateFiles was invented specifically for such cases , you can even process it in parallel (if the CPU is bounded):

Parallel.ForEach(Directory.EnumerateFiles(path, "*.txt"), Console.WriteLine); // flood stdout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question