Please use the script to get files by specific extension from all level of sub-folder of given folder
def findFilesByExtensionRecursively(recPath, Ext):
import os
ls = []
if os.path.exists(recPath):
for root, dirs, files in os.walk(recPath):
for fname in files:
if fname.endswith(Ext):
ls.append(fname)
return ls
else:
return 'Please provide valid path!'
if __name__ == '__main__':
c = 0
print 'File Name: '
for i in findFilesByExtensionRecursively('C:\Users\Andrews\Downloads', '.exe'):
print i
c += 1
print '
'
print 'Number of Files: ',c
Sample Output: