xcode自带的也不错
截屏2021-11-11 上午10.03.15.png
#!/usr/bin/env python
#-*- coding:UTF-8 -*-(添加)
import os
import re
class SearchFile(object):
def __init__(self,path='.'):
self._path=path
self.abspath=os.path.abspath(self._path)
def findLine(self,path):
findMusic='assign\)( *)NS[SAMD]';
MusicLine=0;
# print(path)
f = open(path,'r',encoding='utf-8',errors ='ignore')
for lines in f.readlines():
MusicLine=MusicLine+1;
# if lines.find(findMusic)!=-1:
# print(lines)
res = re.search(findMusic,lines)
if res is not None:
print(lines)
#print(lines,end='')
f.close()
def findfile(self,keyword,root):
filelist=[]
for root,dirs,files in os.walk(root):
for name in files:
fitfile=filelist.append(os.path.join(root, name))
# print(os.path.join(root, name))
# print('...........................................')
for i in filelist:
if os.path.isfile(i):
# print(i)
self.findLine(i);
def __call__(self):
while True:
workpath=input('Do you want to work under the current folder? Y/N:')
if(workpath == ''):
break
if workpath=='y' or workpath=='Y':
root=self.abspath
# print('当前工作目录:',root)
dirlist=os.listdir()
# print(dirlist)
else:
root=input('please enter the working directory:')
# print('当前工作目录:',root)
keyword=input('the keyword you want to find:')
self.findfile(keyword,root)
if __name__ == '__main__':
search = SearchFile()
search()
运行效果
截屏2021-11-08 下午1.55.33的副本.png