The most practical method I have yet found to efficiently fill my Blu-ray discs.
I am making a list of fully qualified paths for all available files for writing.
Then (arbitrarily) decide how many directory levels should be considered to group or accept a command line parameter for it. This is necessary so that directories filled with the same elements are combined on one blu-ray. There is also the STUFF option for inserting the largest files in the first place, and when the file causes an overflow, look at the next smaller one until you finish the files or space.
Make a hash with each directory as a key and the total size of the files that it contains as data. Also keep a parallel hash with the number of files in the directory, since free space and directory overhead are likely to add up and should be taken into account.
Choose 22 as the magic number. If you have <= 22 directories, try all combinations to find the closest, but no more than 25.025 GB. If you have more than 22, just use the 22 largest. I use the Perl Algorithm :: Combinatorics module to search for all combinations. Through a trial version and mainly a mistake, I decided that combinations of 21 items took just a few seconds. 23 subjects take many minutes, which is more than my attention. 22 takes about 35 seconds.
The output directory is also accepted and checked for existing data. It is possible to move files (copy, check size and detach).
Each time I bought a new hard drive, it was usually twice as large as the previous one, so I would just copy everything. With Nikon D800E (Extreme!), HDR and Panoramas, I finally ran out of free space.
My project was the unique, weedy and consolidation of the 15-year-old cost of [mostly unwanted] photos, videos, films, music, etc. I took an inventory of about a dozen storage devices, calculated the MD5 signatures, and put them into the database. I chose one drive as the master for the photo and one for the video, and everything else. I found 8 instances of some things!
Now I have about 10 TB of free disk space !!!
Below is a function that does all the real work in case anyone is interested.
================================================= Unfortunately! Your answer cannot be sent because:
Your post appears to contain code that is not properly formatted as code
The stupid website has distorted my original code. Sorry: (..