zoukankan      html  css  js  c++  java
  • python写了个小工具

    源码太多,看的头疼。在目录里找含有某个字符串的文件。结果写到result.txt中

    import os
    import codecs


    fileinfo=open('result.txt','w')  #结果目标文件

    #遍历目录,查找目标,将结果写到result.txt中
    # dir 目录
    # target 要查找的字符串
    # type 文件类型
    #
    def walk_dir(dir,target,type,topdown=True):   
    for root, dirs, files in os.walk(dir, topdown):
    for name in files:
    if name.find(type)==(len(name)-len(type)):
    f=codecs.open(os.path.join(root,name),'r','UTF-8')
    for line in f.readlines():
    if line. find(target)!=-1:
    print (os.path.join(root,name))               
    fileinfo.write('  ' + os.path.join(root,name) + '\n')
    #dir = raw_input('please input the path:')
    #target=raw_input('please input the target:')
    #type=raw_input('please input the file type:')

    dir=r"C:\Users\T\Documents\Flex Builder 3\Pegasus"  #目录
    target="Dlg_Edit_Supplier"                          #目标字符串
    type="as"                                           #文件类型
    walk_dir(dir,target,type)

    参数直接写在里面
  • 相关阅读:
    A promise tomorrow is worth a lot less than trying today.
    时间相关函数
    JAVA中日期格式转换各个字母代表含义
    参考链接
    修饰器
    最新提案
    ArrayBuffer
    读懂 ECMAScript 规格
    使用markdown写博客
    linux系统界面转换
  • 原文地址:https://www.cnblogs.com/macula7/p/1960410.html
Copyright © 2011-2022 走看看