Contents of the dir as below
C:\Test\newtext.txt
C:\Test\Test1
C:\Test\Test1\newtext.txt
C:\Test\Test2
The count variable is getting printed three times. Why is it getting printed 3 times?
import os
dir = 'C:\\Test'
print(os.listdir(dir))
count = 0
def filepath(dir):
global count
for path in os.listdir(dir):
childPath = os.path.join(dir,path)
if os.path.isdir(childPath):
filepath(childPath)
else:
count += 1
print(childPath)
print(count)
filepath(dir)