Why not implement a function that takes a list of files or directories and tells you which of them fits best within a certain size limit?
Imgburn will calculate the optimal combinations, and then give the option to burn the combinations.
Just specify the size to use and how close to 100% you want to fill it, select the files or directories to use as "candidates," and click Compute. The results will appear, and you can move or copy the winning combination to another location prior to burn.
See you.