2017-05-22 33 views
-1

在我有一個未知的xlsm文件的文件夾中,我如何使用python代碼來執行一些搜索並打印出xlsm文件的編號。如何使用python代碼搜索文件夾中xlsm文件的數量?

任何人都可以與我分享想法?

+2

我會先寫一些代碼。 – timgeb

+2

你可以使用listdir + fnmatch。 看看這個:https://docs.python.org/3/library/fnmatch.html#fnmatch.fnmatch – Nilanjan

+0

'xlsm文件的數量'意味着什麼?它的內容?名稱?一些元數據? – gonczor

回答

1
fileCounter=0 

for root, dirs, files in os.walk(myPath): 
    for file in files:  
     if file.endswith('.xlsm'): 
      fileCounter+= 1 

print("The number of .xlsm files in your directory is: ",fileCounter) 
相關問題