Match files that match pattern in Groovy and Python

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 )































以上是关于Match files that match pattern in Groovy and Python的主要内容,如果未能解决你的问题,请参考以下文章

VS2012 No exports were found that match the constraint

docker0: iptables: No chain/target/match by that name错误处理

Input ‘filename‘ of ‘ReadFile ‘Op has type float32 that does not match expected type of string

docker运行报错docker0: iptables: No chain/target/match by that name.

Input ‘filename‘ of ‘ReadFile ‘Op has type float32 that does not match expected type of string

MVC 区域内默认控制器不能访问(Multiple types were found that match the controller named ‘Index')