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)

    参数直接写在里面
  • 相关阅读:
    第一天开通博客,记录自己在编程道路上的点点滴滴
    一个非常棒的jQuery 评分插件--好东西要分享
    jquery.easing的使用
    SEO优化
    nodejs(三)下之mangoDB
    nodejs(三)上之express
    nodejs(二)
    nodejs(一)
    angular(二)
    angular(一)
  • 原文地址:https://www.cnblogs.com/macula7/p/1960410.html
Copyright © 2011-2022 走看看