Discuss / Python / 第二题,os.path.isdir()里的路径是否要写完整路径就是用os.path.join(dir,file)?

第二题,os.path.isdir()里的路径是否要写完整路径就是用os.path.join(dir,file)?

Topic source

纟彖来

#1 Created at ... [Delete] [Delete and Lock User]

import os

def searchfile(dir,str): #str为指定字符串 for file in os.listdir(dir): #当前目录下所有目录文件 full_path=os.path.join(dir,file) if os.path.isdir(full_path): #如果是目录 searchfile(full_path,str) elif os.path.isfile(full_path): #如果是文件 r=file.find(str) #检查是否包含字符串 if r!=-1: print(full_path) #打印文件路径

互相学习,请各位同学拍砖


  • 1

Reply