October 8, 201213 yr Hi I set a variable with RegisterGroovy( "List_All_Files_In_Directory ( path )" ; "def result = new StringBuffer(); def dir = new File(path); count = 0; listFiles( dir, result ); result.toString().trim(); void listFiles( File directory, StringBuffer buff ) { for (eachFile in directory.listFiles() ) { if (eachFile.getName().startsWith(\".\")) continue; buff.append(\"\n\" + eachFile.getPath()); if( eachFile.isDirectory() ) { buff.append( File.separator ); } count++; } } ") and get error org.codehaus.groovy.control.MultipleCompilationerrorsException: startup failed: Script1.groovy: 1: unexpected token: count @ line 1, column 389. pend( File.separator ); } count++; ^ 1 error
October 8, 201213 yr Author perhaps it is the n character wich failed I've tried "n" or "n" without success
October 8, 201213 yr Did you test the code as a ScriptMaster module first to confirm the code will compile?
October 8, 201213 yr Author if i put this code in a field and put into the groovy quote (field), it works. I think it is probably the character, but i don't so now i put : RegisterGroovy( "List_All_Files_In_Directory ( path )" ; quote ("def result = new StringBuffer(); def dir = new File(path); count = 0; listFiles( dir, result ); result.toString().trim(); void listFiles( File directory, StringBuffer buff ) { for (eachFile in directory.listFiles() ) { if (eachFile.getName().startsWith(".")) continue; buff.append("n" + eachFile.getPath()); if( eachFile.isDirectory() ) { buff.append( File.separator ); } count++; } }") ) and it works !
October 8, 201213 yr Author in fact it records well, but the function does not work error : def result = new StringBuffer(); def dir = new File(path); count = 0; listFiles( dir, result ); result.toString().trim(); void listFiles( File directory, StringBuffer buff ) { for (eachFile in directory.listFiles() ) { if (eachFile.getName().startsWith(".")) continue; buff.append(" " + eachFile.getPath()); if( eachFile.isDirectory() ) { buff.append( File.separator ); } count++; } }
October 8, 201213 yr Author now it seems to be right with : RegisterGroovy( "List_All_Files_In_Directory ( path )" ; "def result = new StringBuffer();¶def dir = new File(path);¶count = 0;¶listFiles( dir, result );¶result.toString().trim();¶¶void listFiles( File directory, StringBuffer buff ) {¶ for (eachFile in directory.listFiles() ) {¶ if (eachFile.getName().startsWith(".")) continue;¶ buff.append("n" + eachFile.getPath());¶ if( eachFile.isDirectory() ) {¶ buff.append( File.separator );¶ }¶ count++;¶ }¶}")
October 8, 201213 yr Author it works in a calculating field, bu the dataviewer don't like this function
October 8, 201213 yr This is a great example where being more Groovy in the code will help troubleshooting: Using if (eachFile.getName().startsWith('.')) in the code will show the same in the RegisterGroovy code rather than the escaped version, making it much easier to read.
Create an account or sign in to comment