腳本檢測assign的NSString等屬性

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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容