I a script that processes files from a folder calles source
. As I process these files in batches I need to verify that at least n
files are in source
. The problem is that source
possibly contains a few hundred thousand or millions of files, thus len(os.listdir(src))
is too slow for my needs.
I've considered having a function that os.walk
s in source
until the number if minimum required files reached, then returns True
, else False
. I just tested walk really quick
for rwalk,dwalk,fwalk in os.walk(C:\\tmp\\folder\\):
for f in fwalk:
print(f)
which blurts out in tons of information even if C:\\tmp\\folder\\
only contains a handful of files.
How can I have a function that checks if at least n
files are in source
without listing every contained file first?