python遍历文件夹找出文件夹后缀为py的文件方法
2019/7/15 0:05:42
本文主要是介绍python遍历文件夹找出文件夹后缀为py的文件方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
大学毕业, 想看看大学写了多少行代码。
#coding=utf-8 import os class 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.dirPath def 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()
以上这篇python遍历文件夹找出文件夹后缀为py的文件方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于python遍历文件夹找出文件夹后缀为py的文件方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-18Python编程基础
- 2024-10-18Python开发基础:变量与类型
- 2024-10-16Python基础教程:从变量与类型开始
- 2024-10-16Python编程基础与进阶
- 2024-10-16Python编程基础教程
- 2024-10-16Python基础入门指南
- 2024-10-11Python编程基础与实践
- 2024-10-11Python编程基础
- 2024-10-11Python编程基础教程
- 2024-10-11使用Python和FMP API来分析一下绩优股的股息走势。