人蛇大战之蛇国女王,荷兰足球,樱川满月
在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径:
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('.'))
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
新手学习Python2和Python3中print不同的用法
Python基于os.environ从windows获取环境变量
网友评论