Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
75 views
in Technique[技术] by (71.8m points)

How to count number of LOG files in a specific directory using python

I have to make a function that takes a directory path or name and count number of LOG files inside it

question from:https://stackoverflow.com/questions/65879411/how-to-count-number-of-log-files-in-a-specific-directory-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This should work:

def count_log_files(folder):

    return len([f for f in os.listdir(folder) if f.endswith('.LOG')])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...