Discuss / Python / 第二问

第二问

Topic source

ChaselZ0429

#1 Created at ... [Delete] [Delete and Lock User]
import os
def findFileWithStr(path,s):
    for root,dirs,files in os.walk(path):
        for file in files:
            if s in file:
                # lstrip方法未能返回正确结果
                # print(os.path.join(root,file).lstrip(path))
                relativePath=os.path.join(root,file).replace(path,'')
                print('/'+relativePath if relativePath[0]!='/' else relativePath)


  • 1

Reply