groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petersen, Robert" <>
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> class Foo {
groovy>       def java.lang.String path
groovy>       def java.lang.String pattern
groovy>       def java.lang.String replacement
groovy>       def list = []
groovy>       File dir = new File(path)
groovy>         // dir.eachFileRecurse (FileType.FILES)  // gets subdirs
groovy>         dir.eachFile( FileType.FILES)
groovy>         {
groovy>             file ->
groovy>               if ("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 ( 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
View raw message