-1

我有一个脚本:

def tmn_file = ~/.*\.tmn/
def tmc_file = ~/.*\.tmc/
def newTerm = new Properties().with { props ->
    new File(inputPath).eachFile(tmn_file) { file ->
        file.withReader    { reader ->
            load( reader )
            println "Read data from file $file:"
            something read from file...
            switch( props.ACTION ) {
                case 'NEW':
                    do something...
                    }
            switch( props.ACTION ) {
                case 'CHANGE':
                    do something...
                    }

此脚本在目录中查找路径 inputPath 扩展名为 tmn_file 的文件,该文件可以包含 ACTION - NEW 或 CHANGE。

脚本效果很好,但我想做另一件事:

如果文件具有扩展名 *.tmn (tmn_file) - 仅以新案例开始 ACTION

如果文件具有扩展名 *.tmc (tmc_file) - 仅以更改大小写开始操作

我怎样才能实现决定?

4

1 回答 1

1

这是解决方案:

new Properties().with { props ->
    new File(inputPath).eachFile(FileType.FILES) { file ->
        file.withReader { reader ->
            load(reader)
            println "Read data from file $file:"

            if (file.name.endsWith('tmn') & props.ACTION == 'NEW' || file.name.endsWith('tmc') & props.ACTION == 'CHANGE') {

// NEW mode
                switch( props.ACTION ) {
                    case 'NEW':
                        ...do someth...
                        break

// CHANGE mode    
                    case 'CHANGE':
                        println "***CHANGE mode is on***"
                        ...do someth...
                        break
                    default:
                        throw new RuntimeException("Unknown ACTION $props.ACTION")
               }

            }  else {
                if (file.name.endsWith('tmn') || file.name.endsWith('tmc')){
                println "$file dont match for action $props.ACTION"
                } else {
                println "$file have wrong extension "}
            }
    }
    }
}
于 2013-05-22T05:21:47.447 回答