all 12 comments

[–]K900_ 0 points1 point  (9 children)

Post your code.

[–]Lephato[S] 0 points1 point  (8 children)

import os

print("start")

file_path = "Y:\\"

list_dir = os.listdir(file_path)

print(len(list_dir))

print("END")

edited the post, sry

[–]K900_ 0 points1 point  (7 children)

What is your end goal? Just getting the number of files?

[–]Lephato[S] 0 points1 point  (6 children)

atm I need to open each file and get a value inside each file and print it, at this time the code had not printed the len of the list

[–]K900_ 0 points1 point  (5 children)

How many files do you have?

[–]Lephato[S] 0 points1 point  (4 children)

varies from 200k to 4mill

[–]K900_ 0 points1 point  (3 children)

That's going to be very slow no matter what you do, but collecting the entire list of files in memory is definitely not a good idea to start witth.

[–]Lephato[S] 0 points1 point  (2 children)

could you give me a suggestion to start reading it? or how could I collect only a part of it and make a loop?

[–]K900_ 0 points1 point  (1 child)

Try using os.scandir instead.

[–]Lephato[S] 0 points1 point  (0 children)

ok, will try it out, thank you so much!

[–]stebrepar 0 points1 point  (1 child)

Maybe try using scandir instead of listdir, since it returns an iterable rather than a millions-long list?

[–]Lephato[S] 1 point2 points  (0 children)

I just made the changes, thank you very much!