import os
def myfile(path,postfix,reldir):
for f in os.listdir(path): if os.path.isdir(os.path.join(path,f)):
reldir = os.path.join(reldir,f)
myfile(os.path.join(path,f),postfix,reldir) else:
if f.find(postfix) != -1:
print('相对路径:{},文件名:{}'.format(reldir,f))
magicStockCheck
import os def myfile(path,postfix,reldir): for f in os.listdir(path):
if os.path.isdir(os.path.join(path,f)): reldir = os.path.join(reldir,f) myfile(os.path.join(path,f),postfix,reldir)
else: if f.find(postfix) != -1: print('相对路径:{},文件名:{}'.format(reldir,f))
postfix = 'csv' #指定字符串 myfile(R'D:\dirtest',postfix,'')