Add in new collection if files size sum is 20 MB

Hi guys, i’ve an issue with this workflow.

I’ve a couple of files to attach in a mail and to simplify the life of receivent i want to zip in a unique file. All works fine, but outlook can’t attach a file > of 20/25 MB.

To workaorund this, i’ve think to do a condition like this:

For each item in Directory.GetFiles("PDF");

add to collection ListBatch (list of String)

assign system.IO.fileinfo filesize = New System.IO.FileInfo(item)

Math.Round(filesize.SizeInKB)

add to collection SumBatch (list of int32)

assign Int32 Sum = SumBatch.Sum

If Sum > 20 MB then
Zip ListBatch —> (“C:\user\nameoflist.zip”)

Clear collection

Now the issue is: how i can transform zip name in a variable? To change the name of the zip before the new one overwrite the old one?

And how can i add the value of FileSize in kb to a SumBatch collection?

Thank you!

You can create this List(of Strings).
Create int_Size = 0

After that place this for each file in array:

Inside check size of the file in kb and assign to int_FileSize

Int_Size = int_Size+int_FileSize

If int_Size < 20000
Then add path to collection.
Else:

 Str_fileZip = "zip_"+now.toString("yyyyMMdd_HHmmss")+".zip"
 Archive this collection to zip.
 Clear collection ( new list(of String))
 Int_Size = int_FileSize
 add path to cleared collection

It will add to collection until is less than 20mb.
If there is more it creates zip with unique name, clear collection and add a new file for next package.

Other way to do different names is add number to the file name. Then before for each loop create var:

Int_FileZip = 1

And inside else ( in the right side of if activity) place this values:

  Str_fileZip = 
  "zip_"+Int_FileZip.toString+".zip"
  Archive this collection to zip.
  Clear collection ( new list(of String))
  Int_Size = int_FileSize
  add path to cleared collection
  Int_FileZip = Int_FileZip+1

In that case zip files will have shorter name and it would be zip_1.zip, zip_2.zip etc. :slight_smile:

If you place sth like this:
Str_fileZip =
“C:/Folder/zip_”+Int_FileZip.toString+“.zip”

It will surely work as destination path of the newly created archive path.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.