by Baz Cuda
This flow will cycle through all the files in a selected folder and move them to subfolders so that each subfolder contains approximately 2GBs of files.
There is a built-in tolerance to allow up to 100MB over the 2GB requirement (block 30).
The subfolders will be named after the selected folder with the addition of "01", "02", etc.
More files can be added to the selected folder later and the flow re-run (or the flow can be re-started after an interruption), in which case it will continue with the next subfolder in the sequence, rather than starting again from "01", which would double the size of each folder to 4GBs.
The flow calculates in bytes rather than converting to MBs, so that 1000s of small files, e.g. images, won't appear to be zero in size and all end up in one subfolder.
You can adjust the required folder size in blocks 29 and 30 to your requirements.
The purpose of block 20 is to force the creation of the first subfolder during the very first iteration of the for-each loop, so the first file has somewhere to be moved to. It's a programming technique worth noting. Usually you would set all counts and running totals (totalSize) to zero prior to the loop, and set up any other requirements for the first iteration. You then keep the running totals and react at the end of an iteration when they've reach the predetermined threshold, eg creating the next folder. But that is no good for this flow as the very first file needs to have a subfolder to be moved to even though we currently have zero bytes tallied towards our 2GB threshold. This is easily achieved by turning the loop on its head and setting the threshold to already exceeded (by the +1 in block 20) going into the first iteration of the loop. This then immediately triggers the creation of the destination subfolder and results in some very neat and tidy code.
Block 41 exists purely to obtain the file size. Clearly, the file must exist otherwise Automate wouldn't have included it in the file listing (block 3) given that, thus far, Automate does not appear to exhibit any psychotic tendencies :D
Constructive comments always welcome.