###讨论讨论,多重目录下的目录文件,识别不出来,或者识别不全。
def fileSearch(file,path):
a=[x for x in os.listdir(path) if os.path.isfile(x) and file in x] #在当前目录中:找到文件名包含指定字符串的文件
for x in a:
print(os.path.abspath(x)) #打印出相对路径
b=[x for x in os.listdir(path) if os.path.isdir(x)] #找出当前目录中的dir,得到dir的路径
print(b)
for c in b:
#print(file+' ==>'+c)
#os.path.join(os.path.abspath(c),x)
new=os.path.join(path,c)
print(new)
fileSearch(file,new)
fileSearch('装饰器','.')
Sign in to make a reply
我可能会炸
###讨论讨论,多重目录下的目录文件,识别不出来,或者识别不全。
def fileSearch(file,path):
a=[x for x in os.listdir(path) if os.path.isfile(x) and file in x] #在当前目录中:找到文件名包含指定字符串的文件
for x in a:
print(os.path.abspath(x)) #打印出相对路径
b=[x for x in os.listdir(path) if os.path.isdir(x)] #找出当前目录中的dir,得到dir的路径
print(b)
for c in b:
#print(file+' ==>'+c)
#os.path.join(os.path.abspath(c),x)
new=os.path.join(path,c)
print(new)
fileSearch(file,new)
fileSearch('装饰器','.')