zoukankan      html  css  js  c++  java
  • Match files that match pattern in Groovy and Python

    转自: http://atobs.blogspot.fr/2012/08/match-only-files-that-match-pattern-in.html#!/2012/08/match-only-files-that-match-pattern-in.html

    Groovy:
    In Groovy we can use the eachDirRecurse and eachFileMatch() methods to get all the file names displayed.

    def pattern = ~/.*.java/
    def dirname="/usr/local/mysource"

    new File("$dirname").eachDirRecurse { dir ->

            dir.eachFileMatch(pattern) {    myfile ->
                    println  "$myfile"
            } // eachFileMatch

    } // eachFileMatch


    Python:
    In Python,  we can list each matching file using "glob"

    import os, glob, sys

    for root, dirs, files in os.walk( 'E:\users' ):
        os.chdir (root)

        # find all files that match log*
        logs = glob.glob( '*log*' )
        if logs:
            for fname in logs:
                fullpath = os.path.join ( root, fname )
                # Identify files of len 3 lines long and delete them
                count  = len ( open(fullpath).readlines() )
                if count == 3 or count == 2:
                    print  'Removing ', fullpath
    os.remove ( fullpath )
  • 相关阅读:
    CRM4.0多组织安装和设置
    如何找回你的VirtualPC2007控制台
    线性表
    时间复杂度
    栈与队列
    字符串排序问题
    浙江企业网喜讯之一
    初次体验到C#范型的魅力
    ajax 或 js 异步判断用户名是否存在
    html基础知识1(基本标签)20170307
  • 原文地址:https://www.cnblogs.com/z1500592/p/6020466.html
Copyright © 2011-2022 走看看