A complex logic need your help

Dear all,

I have more than 30 files with total size 45MB, i need to send them out by mails, but the attachments will be limited to 10MB every time, that means i need to send 5 times.

Now I am reading all the files to a array using Directory.GetFiles(FilePath, “.”,SearchOption.AllDirectories), but how to separate this array to 5 arrays and make sure each total size smaller than 10MB ? and then I can send it out by mail with each files array.
thanks so much

What will be the size of the 45 mb file afte zipping it? @413387330

thanks so much for your reply.

I am not sure the size after zipping, but i do not want to zip it since it will be not convenient for our user to open and check it .

You can upload the files to google drive and share the link in mail. Can you do that? @413387330

Hi @413387330

As per me below workflow steps should work :-

  1. Files array will be der in ForEach Activity
  2. I have attached the workflow which will give the file size in MB
  3. After measuring Each file size Just check within If Activity as fileSizeInMB <= 10
    If Yes then create the New List & repeat the loop and add the next file in New List which will consists of the files having size less than 10MB along with that add the file Size also till it gets 10MB to the same variable fileSizeInMB or you can also have any new variable
    If No means if it is greater than 10 MB then within else you will mail the files of the new List created and move those files to another folder just for convenience that one by one as per the files are mailed they are moved to another folder. And after mailing just make the new List Empty and then add the current loop file to the new list and assign variable fileSizeInMB = currentLoopFileSize
  4. Repeat this till all the files are mailed

MainPratik.xaml (8.2 KB)

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi Manish,
I can not do that.
I will send it out by mail, and then another bot will pick it up to upload it to our SAP system.

thanks so much for your solution.
but the big challenge is when we do the for each, perhaps in current loop the total size is 7 MB but next loop it will be more than 10MB .
so it is hard to know in which loop we should send the files out.

Loop through all files.
Use an if-statement to check if the combined size of the files in the list/collection and the current file is more than 10 mb.
If it is send all the files EXCEPT the current one. Empty the list and add the current file to the list/collection.
If it is not more than 10 mb, add the current file to the list/collection.

When you are at your last file, remember to send the list/collection of files. It might contain only the last file and it might contain more files.