import glob
import os
fp = '/Users/../Desktop'
pylist = []
def get_py(fp):
filelist = glob.glob(os.path.join(fp,'*'))
for file in filelist:
if os.path.isdir(file):
get_py(file)
elif os.path.splitext(file)[-1] == '.py':
pylist.append(file)
else:
continue
get_py(fp)
print(pylist)
遇到空文件夹,则返回控制