I am using the scandir
library to look over all files on my computer. I would like to stop the loop once I've checked 100 records. If the yield
statement is never called, my variable, c
never increases and the loop doesn't stop. I've put in some bogus file name thisfilewontbefound
that will never be found thus yield
is never reached. Why is c
not incrementing?
from scandir import scandir, walk
import sys
def subdirs(path):
for path, folders, files in walk(path):
for files in scandir(path):
if 'thisfilewontbefound' in files.path:
yield files.path
c = 0
for i in subdirs('C:\\'):
if c > 100:
print "test over"
sys.exit()
c += 1
print i