vishavjeet

singh.vishavjeet11@gmail.com

How can count python files in given directory?

Posted on July 14, 2021



def count_py_files_in_repos(dirname):
    #os.chdir("D:/deebaco")
   # if os.path.exists(os.path.join(dirname, '.git')):
   if os.path.exists(os.path.join(dirname)):
      count = 0
     for root, dirs, files in os.walk(dirname):
        count += len([f for f in files if f.endswith('.py')])
     print(f"{dirname} has {count} python files.")

    for name in os.listdir(dirname):
       path = os.path.join(dirname, name)
       if os.path.isdir(path):
              count_py_files_in_repos(path)


count_py_files_in_repos('D:/deebaco/apipy/master')


Sign In for comment and like the post.