How do I count only the files in a directory? This counts the directory itself as a file:
len(glob.glob('*'))
countfnmatchglobpython
How do I count only the files in a directory? This counts the directory itself as a file:
len(glob.glob('*'))
Best Answer
os.listdir()
will be slightly more efficient than usingglob.glob
. To test if a filename is an ordinary file (and not a directory or other entity), useos.path.isfile()
: