count files in folder python code example
Example 1: python count files directory
import os
len(os.listdir(directory))
Example 2: count a number of file in a folder python
import os
len([item for item in os.listdir(folderPath)])
Example 3: python monitor directory for files count
import os.path
path = os.getenv('HOME') + '/python'
num_files = len([f for f in os.listdir(path)if os.path.isfile(os.path.join(path, f))])