import os onlyfiles = next(os.walk(dir))[2] #dir is your directory path as string print len(onlyfiles)