如何处理if-else在groovy? [英] how to handles if-else in groovy?

查看:184
本文介绍了如何处理if-else在groovy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果skipfolders为true,那么我会在输入中传递 skipfolders 变量,然后从父路径打印所有文件并跳过子文件夹。
,否则它将返回所有文件夹中的所有文件,包括子文件夹。这里我写了if-else条件。当我在 FileMaker
中执行这段代码时,它执行时没有任何错误并显示结果,但if-else条件在这里不起作用。

Here I'm passing the skipfolders variable in input if the skipfolders is true then it prints all files from Parent path and skip the sub folders. otherwise it returns all files from all folders include sub folders as well. Here I wrote if-else conditions. When I execute this code in FileMaker it executes without any errors and displayed result.but the if-else conditions does't working here.

如果其他条件不起作用here.it从FTP打印所有文件include子文件夹.skipfolders条件doesn没有工作。
在此返回allFiles.join('\ n')+'\ n'+ allFolderFiles.join('\ n')+'\ n'直接打印并且skipfolders条件不起作用。
请帮助如何在fileMaker groovy中正确使用if-else条件。

If-else conditions doesn't working here.it prints all files from FTP include subfolders.skipfolders condition doesn't working. at this return allFiles.join('\n') + '\n'+ allFolderFiles.join('\n')+ '\n' prints directly and skipfolders condition doesn't working. Please help how to use if-else conditions properly in fileMaker groovy.

start()
def start(){

        boolean skipfolders = false
        def store;
        def ftpClient = new FTPClient()
        ftpClient.connect(server)
        // println(ftpClient.replyString)
        ftpClient.login(user,pass)
        ftpClient.enterLocalPassiveMode()
        FTPFile[] fileslist = ftpClient.listFiles("/")
        FTPFile[] folderfileslist = ftpClient.listFiles("/sample")

  if(skipfolders == false){

       def allFiles = []; 
       for(int i=0; i<fileslist.length; i++){  
       String file_name = fileslist[i].getName()
       String file_timestamp = fileslist[i].getTimestamp().getTime()     
       String s = '|' + file_name+ '|' + '/' +file_name+'|'  +file_timestamp
       allFiles << s       
   }  
      def allFolderFiles = [];
      for(int i=0; i<folderfileslist.length; i++){
      String folderfile_name = folderfileslist[i].getName()
      String folderfile_timestamp = folderfileslist[i].getTimestamp().getTime()
      String s1 = '|' +folderfile_name+ '|' + '/sample' +'|'+folderfile_name+'|'  +folderfile_timestamp
      allFolderFiles << s1
 }
  ftpClient.disconnect()
  return allFiles.join('\n') + '\n'+ allFolderFiles.join('\n')+ '\n'

}
else{
       def allFiles = []; 
       for(int i=0; i<fileslist.length; i++){  
       String file_name = fileslist[i].getName()
       String file_timestamp = fileslist[i].getTimestamp().getTime()     
       String s = '|' + file_name+ '|' + '/' +file_name+'|'  +file_timestamp
       allFiles << s       
   }  
   ftpClient.disconnect()
   return allFiles.enter code herejoin('\n')
  }
}

    enter code here

if anybody having idea please let me know thanks.


推荐答案

如果我正确理解问题,设置skipfolders变量作为参数。

If i am understanding the question correctly, you want to set the skipfolders variable as a parameter.

因为您已经声明:

As it is you have declared:

boolean skipfolders = false;

因此,在问题评论中,用户daggett从未达到else。

So the else is never reached as mentioned by user daggett in the question comment.

如果你这样做:

If you do something like this instead:

start(true) or start(false)
def start(boolean input){
    boolean skipfolders = input;
    ...
}

然后,您可以根据你的意见。

Then you can reach the else statement depending on your input.

这篇关于如何处理if-else在groovy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆