ftp automation

ScriptFTP

The professional tool to automate FTP, SFTP, FTPS and schedule FTP batch jobs

The forum is now read only. Please, go to the the main ScriptFTP website if you need help.
Need help writing a script? Have any question about ScriptFTP?
Hi all.

I need to check if countelements is even or odd because only if it is even i must download the files.

Can anybody help me?

Best Regards
Hi Mauri,

Yes, there is a way to do that. But I must say that it is a very strange method. As the ScriptFTP script language is very limited (it is meant to be easy to learn) these kind of integer operations are not well supported. This is the workaround to do this:


FTP Script
  1. # Changing current local folder
  2. LOCALCHDIR("C:\Users\Carlos\Desktop")
  3.  
  4. # Get the list of the files in this folder
  5. GETLIST($list,LOCAL_FILES,"*.*")
  6.  
  7. # How many files?
  8. $n = COUNTELEMENTS($list)
  9.  
  10. # is n even or odd?
  11. IF(($n/2)==(($n+1)/2))
  12.     PRINT("n is even")
  13.     # Download the files
  14.     PRINT("n is odd")


You can check if 'n' is even or odd comparing the result of n/2 and (n+1)/2. If the number is even the result is the same, if not it is an odd number. Also, '/' means the integer division, not the kind of division that gives you decimals.

Attached is a small hand written table that may help to understand how it works. If you are curious.
Attachments
even_or_odd.png
even_or_odd.png (135.8KiB)Viewed 3284 times
Thank you very much.
Well done.
Bye.