1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python遍历文件夹找出文件夹后缀为py的文件

python遍历文件夹找出文件夹后缀为py的文件

时间:2020-03-13 17:27:02

相关推荐

python遍历文件夹找出文件夹后缀为py的文件

大学毕业, 想看看大学写了多少行代码。

#coding=utf-8import osclass Solution:def __init__(self):self.dirPath = []def numberOfCode(self,path):for dir in os.listdir(path):childDir = os.path.join(path,dir)if os.path.isdir(childDir):self.numberOfCode(childDir)else:if childDir[-2:] == "py":self.dirPath.append(childDir)return self.dirPathdef setCode(self):with open("/home/code.py","ab+") as f:for file in self.dirPath:content = open(file,"r").read()f.write(content)s = Solution()s.numberOfCode("/home/py/")s.setCode()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。