#!/opt/anaconda3/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
def show_files(path, all_files):
# 首先遍历当前目录所有文件及文件夹
file_list = os.listdir(path)
# 准备循环判断每个元素是否是文件夹还是文件,是文件的话,把名称传入list,是文件夹的话,递归
for file in file_list:
# 利用os.path.join()方法取得路径全名,并存入cur_path变量,否则每次只能遍历一层目录
cur_path = os.path.join(path, file)
# 判断是否是文件夹
if os.path.isdir(cur_path):
show_files(cur_path, all_files)
elif file.find(".m") >= 0:
all_files.append(cur_path)
return all_files
def handleTableViewCellContentAddSubview(file_path):
f = open(str(file_path))
file = f.readlines()
lineNumber = 0
x = 0
y = 0
for line_item in file:
lineNumber = lineNumber + 1
if 'initWithStyle:' in line_item:
x = lineNumber
if '[self addSubview:' in line_item:
y = lineNumber
if x > 0 and y > 0:
print("find the add subtview content")
print(file_path + " inline:[" + str(y) + "]")
print("##################################################")
f.close()
# 传入空的list接收文件名
contents = show_files("/Users/zhangyuqing/Desktop/zuche/wccgeneralui", [])
# 循环打印show_files函数返回的文件名列表
for content in contents:
handleTableViewCellContentAddSubview(content)