import os
def fileCount(folder):
"count the number of files in a directory"
count = 0
for filename in os.listdir(folder):
path = os.path.join(folder, filename)
if os.path.isfile(path):
count += 1
elif os.path.isdir(path):
count += fileCount(path)
print(folder,'having',count)
return count
fileCount('.')
import glob
def countMe(MyPath,typeofFile):
numInstances = len(glob.glob1(MyPath,'*.'+typeofFile))
return numInstances
typeofFile
应该是您正在查找的扩展名的字符串。如果您正在寻找.pdf
,则typeofFile = 'pdf'