一个类中的代码片段,记录一下自己的递归实现,以备后查。
-
def loadingYamlFile(self, pathstr: str) -> str:
-
oldcurpath = self.curpath
-
if self.level == 0:
-
self.curpath = self.targetpath
-
else:
-
self.curpath = self.curpath + "\\" + pathstr
-
files = os.listdir(self.curpath)
-
for f in files:
-
if os.path.isdir(self.curpath + "\\" + f):
-
if f[0] == ".":
-
pass
-
else:
-
self.level = self.level + 1
-
self.curpath = self.loadingYamlFile(f)
-
-
if os.path.isfile(self.curpath + "\\" + f) and "yaml" in f:
-
filename = self.curpath + "\\" + f
-
self.yamlfilelist.append(filename)
-
return oldcurpath
阅读(648) | 评论(0) | 转发(0) |