groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petersen, Robert" <robert.peter...@rakuten.com>
Subject Re: why does this throw an exception? new to groovy, script works outside of class def
Date Wed, 29 Mar 2017 01:42:35 GMT
groovy> import groovy.io.FileType
groovy> class Foo {
groovy>       def java.lang.String path
groovy>       def java.lang.String pattern
groovy>       def java.lang.String replacement
groovy>       def list = []
groovy>
groovy>       File dir = new File(path)
groovy>
groovy>         // dir.eachFileRecurse (FileType.FILES)  // gets subdirs
groovy>         dir.eachFile( FileType.FILES)
groovy>         {
groovy>
groovy>             file ->
groovy>               if (file.name.endsWith("txt")) list << file
groovy>         }
groovy>   }
groovy> // this works
groovy> def f = new Foo(path: "L:\\tmp", pattern: "this", replacement: "that")
groovy> println f.path
groovy> println f.pattern
groovy> println f.replacement
groovy> //Afterwards the list variable contains all txt files (java.io.File) of the given
directory (and its subdirectories with Recurse):
groovy> f.list.each {
groovy>   println it.path
groovy> }

1 compilation error:

unexpected token: dir at line: 13, column: 9
Mime
View raw message