Discuss / Python / 查找文件名包含指定字符串

查找文件名包含指定字符串

Topic source

冬凉默殇

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os

def myfind(patten, root='.'):
    for each in os.listdir(root):
        if os.path.isdir(os.path.join(root, each)):
            myfind(patten, os.path.join(root, each))
        if patten in str(each):
            print(os.path.join(root, each))

  • 1

Reply