Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python count files fast

import os
dir_path='C:/route/to/dir'
# Example 1: Non-recursive
tree=os.walk(dir_path, topdown=True)
top_branch=next(tree)
print(len(top_branch[2]))   
# The result is 3
# Example 2: Non-recursive (a more compact form)
tree=os.walk(dir_path, topdown=True)
print(len(next(tree)[2]))   
# The result is 3  
# Example 4: Recursive
num=0
for i in os.walk(dir_path, topdown=True):
    num += len(i[2]) 
print(num)   
# The result is 4

# any of these is equaly fast
Comment

PREVIOUS NEXT
Code Example
Python :: linkedin python test 
Python :: registration of the path django urls in the core app or main app 
Python :: Algorithms and Data Structures in Python (INTERVIEW Q&A) 
Python :: strain rate 
Python :: affochage dun index du array list a deux dimension 
Python :: python sumproduct excel 
Python :: convert float array to integer 
Python :: dataframe ggplot rownames order 
Python :: apropos, help 
Python :: python run docker interactively subprocess 
Python :: Python NumPy atleast_1d Function Example 
Python :: jupyter extension 4 
Python :: how to make dinamic table in jinja python 
Python :: Python NumPy asanyarray Function Syntax 
Python :: Python NumPy block Function Example by using simple array 
Python :: making dividers in tkinter 
Python :: structure conditionnelle python 
Python :: __sub__ 
Python :: NumPy rot90 Example Rotating Twice 
Python :: how to increment date in python 
Python :: python subprocess redirect a file 
Python :: flatten a list using numpy and itertools 
Python :: first index of an integer less than a value 
Python :: how to swap a lowercase character to uppercase in python 
Python :: rasa emotion bot 
Python :: combobox write disable tkinter 
Python :: python if corto 
Python :: SQLAlchemy ordering by count on a many to many relationship 
Python :: DD python ue5 set material interface 
Python :: list foreach pyhton 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =