How to zip files in set of 10 only?

I am having 29 files in a folder. I want to zip them in set of 10 i.e. as output I should get 3 zip files. Layout :

1st zip: 10 files
2nd zip: 10 files
3rd zip: 9 files

Can anyone Help? Thanks In Advance :blush:

Hi,

Hope the following helps you.

Sequence2.xaml (10.4 KB)

Regards,

Thankyou so very much @Yoichi. It is working for me. It would be really helpful if you can explain this nested for each.

Hi,

Outer For each is for result zip files.

(files.Count \ num)+1 returns division quotient of all files and num(in this case 10)
This means number of result zip files.

Inner For each is for files of single zip file.

files.Skip(item*num).Take(num) returns num files from (item*num) th.
These num files is copird to temp folder then be compressed.

Hope this helps you.

Regards,

I just checked if there are 20 files it is creating 3 zip file i.e. one empty @Yoichi

Oh, sorry. I didn’t handle properly if mod=0.

Can you modify Value (In) property of outer ForEach as the following

Enumerable.Range(0,(files.Count \ num)+1+CInt(files.Count mod num = 0))

or try the following xaml?

Sequence2v2.xaml (10.5 KB)

Regards,

Hi @Yoichi This worked. Thankyou so much for this. I m stuck with one more situation I would be very grateful if you can help on that too.

So @Yoichi now I want zip files based on their size. Say if 1st File Size + 2nd File size <= limit size then compress those two files only. And repeat the same process for rest files in that folder.

You’ll have to get a variable for Number of Files, say IntNumberOfFiles and you’ll have to replace the expression in For loop. Before loop you can use that expression and mod 10 to get the number of loops, say intNumbrOfLoops, possibly required Then use the variable in do while with y the condition of a counter variable <= the intNumbrOfLoops

in the inner loop after zip is created check the size, if it’s greater than threshold you want, move ahead without increasing any loop counter, just decrement the value of intNumberOfFiles and loop back, if the file size is proper, you can increment the value of intNumbrOfLoops and move ahead.

For picking correct files, you’ll have to either use the logic of skip in expression, for that you’ll have to get another variable just like created already

else you can move the files that are zipped from that folder to make it clear that files in that folders are to be zipped.

once you build this you’ll understand how you need to tackle the resetting of the intNumberOfFiles variable

Hi @rahulsharma If possible can you provide a xaml for that. It would be better understanding.

Hi,

As it seems you create new topic for this, I’ll reply in it.

Regards,

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