Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Difference between file and scriptmaster RegisterGroovy

Featured Replies

Hello
( excuse my english, I'm French ;) )
I use scriptmaster file to develop functions.
However, I observe that sometimes a function works fine in the file and not when I record with RegisterGroovy, and the reverse is also true.
for example this function works properly when it is saved with RegisterGroovy, not in the file.
how to develop functions properly in this uncertain environment
?
what is this error ?
the code example :
 

    import java.util.zip.ZipOutputStream  
    import java.util.zip.ZipEntry  
    import java.nio.channels.FileChannel  
     
    String zipFileName = Zip_path
    String inputDir = Dir_path  

     Try { 
    ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(zipFileName))  
    new File(inputDir).eachFile() { file ->  
    zipFile.putNextEntry(new ZipEntry(file.getName()))  
    def buffer = new byte[1024]  
    file.withInputStream { i ->  
    def l = i.read(buffer)  
    // check whether the file is empty  
    if (l > 0) {  
    zipFile.write(buffer, 0, l)  
    }  
    } 
    zipFile.closeEntry()  
    } 
    zipFile.close()
} catch(Exception e){
         // if any error occurs
         e.printStackTrace()
}

and the error of scriptmaster file

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

Script1.groovy: 24: expecting EOF, found 'catch' @ line 24, column 7.

       } catch(Exception e) {

         ^

…just a matter of typo, your script will compile flawlessly if you write the symbol 'Try' of the try-catch statement in lowercase.

  • Author

Yes it is > thanks Clem
Now I try to inject a wrong dir path and scriptmaster file does't return any error
why ?
you develop codes preferentially with an IDE?
I just tried the groovy console and it looks to be working well


 

  • Author

removing the "e.printStackTrace ()" and replacing it with "return 'erreur'" it works and if I put 'error' scriptmaster opens an empty window :)


but it does not prevent to create an empty zip
I will see controlling the directory before with an if

  • Author

well
this code works fine without writing the zip if there's error
 

//ZipFolder ( Dir_path ; Zip_path )
    import java.util.zip.ZipOutputStream  
    import java.util.zip.ZipEntry  
    import java.nio.channels.FileChannel  
     
    try { 
   
   File f = new File ( Dir_path )
   
   if ( f.isDirectory() ) {
   
    ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(Zip_path))  
    new File(Dir_path).eachFile() { file ->  
    zipFile.putNextEntry(new ZipEntry(file.getName()))  
    def buffer = new byte[1024]  
    file.withInputStream { i ->  
    def l = i.read(buffer)  
    // check whether the file is empty  
    if (l > 0) {  
    zipFile.write(buffer, 0, l)  
    }  
    } 
    zipFile.closeEntry()  
    } 
    zipFile.close()
    }
    else {
    return "erreur"
    }
    }
    catch(Exception e) {
         // if any error occurs
    return "erreur" //e.printStackTrace()
    }

 

well

this code works fine without writing the zip if there's error

 

 

… but will fail if your target directory contains subdirectories.

  • 3 weeks later...
  • Author

Hi
Thank s Clem, it's true
I saw solutions there

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.