在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径:

import os
testfiles = []
testfilepaths = []
L = len(os.path.abspath('.'))

def searchfile(path):
    for item in os.listdir(path):
        if os.path.isdir(os.path.join(path, item)):
            searchfile(os.path.join(path, item))
        else:
            if 'test' in item:
                print(item, path[L:])

searchfile(os.path.abspath('.'))
内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!