import os, os.path
print(len([name for name in os.listdir('.') if os.path.isfile(name)]))
DIR = '/tmp'
print(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(
    DIR, name))]))
How to count the number of files in a directory using Python