Skip to content

Instantly share code, notes, and snippets.

@ayuLiao
Last active August 3, 2018 13:19
Show Gist options
  • Save ayuLiao/4fd0da374d2b9d62659bed097e6cb911 to your computer and use it in GitHub Desktop.
Save ayuLiao/4fd0da374d2b9d62659bed097e6cb911 to your computer and use it in GitHub Desktop.
python统计文件夹中的文件数
#统计文件夹下文件的数目
import os
DIR = '/tmp' #要统计的文件夹
print(len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment