I tried to use the following example but it is not working when I'm adding a new file to the directory:
linecount = 0
path = input()
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith('.py'):
with open(file, 'r') as file:
for line in file:
linecount += 1