John Doe
John Doe

Reputation: 147

Groovy local file extension

Newbie question. How in MarkUpBuilder load local file with specific extension(sql) ?

import groovy.io.FileType
import groovy.xml.*

def sw = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(sw)

def dir = new File("C:\\Users\\John\\git\\changelogs\\version1")


xml.dataBaseChangeLog(){
    dir.eachFileRecurse(FileType.FILES).eachFileMatch(~/.*.sql/) { file ->   
----------------------------------------------------------^ <- //It's bad
            changeSet(author:"John", ID:"JIRA", failOnError: "True", runAlways: "false")
            sqlFile(path:file, relativeToChangelogFile: "true", encoding: "utf8")    
            rollback(){       
                sqlFile(path:file, relativeToChangelogFile: "true")
    }}}
    println sw

Upvotes: 0

Views: 1222

Answers (1)

daggett
daggett

Reputation: 28564

in your code there is an obvious error:

there is no java.io.File.eachFileRecurse() with just one argument: groovy.io.FileType

see javadoc: http://docs.groovy-lang.org/latest/html/gapi/groovy/io/FileType.html

the simple solution:

dir.eachFileRecurse(FileType.FILES){
    if(it.name =~/\.txt/ ){
        println "$it"
    }
}

Upvotes: 1

Related Questions