Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

Problem :

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(' ') + ' '+ allFolderFiles.join(' ')+ ' ' 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('
') + '
'+ allFolderFiles.join('
')+ '
'

}
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('
')
  }
}

    enter code here

if anybody having idea please let me know thanks.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
184 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...