Click here to Skip to main content
15,748,930 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to make code using python from which i can count the directories which is in a directory and the files in it.i am getting number of files and filenames by using listdir() function and count also by using len(data) function.but i have directories in a directory & in that i have files. i am using below code.<br>please guide me for that
<pre><br>
example of ans=(Dir_name 56)

What I have tried:

import os
img_folder_path = ("C:/Users/Uname/Desktop")
dirListing = os.listdir(img_folder_path)
  print(dirListing)
  print(len(dirListing))
Posted
Updated 16-Mar-19 5:36am

 
Share this answer
 
Comments
CPallini 16-Mar-19 11:34am    
5.
I addition to Richard's solution, I would suggest you having a look at os.walk[^] (see the code sample).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900