首页 > 编程知识 正文

linux查找文件夹下的文件是否含有某个字段

时间:2023-05-05 09:38:14 阅读:235724 作者:687

#!/usr/bin/python# -*- coding:utf8 -*-import ossub_str = "interface TenGigabitEthernet"#def get_file_content(file): #filecon = open()def get_dir(path): files = os.listdir(path) for file in files: if file[0] == '.': pass if os.path.isdir(file): get_dir(path+'/'+file) else: file_name = path + '/' + file with open(file_name) as file_obj: for content in file_obj: if content.find(sub_str) != -1: print(file_name)if __name__ == '__main__': # file_content = open("file_content.txt", "wb") path = "/root/v2.75" get_dir(path)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。