vnpenguin has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have a data about 2G with many of files and sub-folders (/tmp/MyDir). I would like to make 3 or 4 iso CD from them with a condition: a sub-folder can not be splitted into 2 CD. Is there a Perl script to do that automatically ? I mean that this script allows me to create :
/tmp/cd1
/tmp/cd2
/tmp/cd3
/tmp/cd4
from /tmp/MyDir. So I could run mkisofs later to make iso. I already done a search on perlmonks site, but no solution. Thanks,
  • Comment on Split file/folder structure to make iso CD

Replies are listed 'Best First'.
Re: Split file/folder structure to make iso CD
by marto (Cardinal) on Apr 04, 2006 at 15:23 UTC
Re: Split file/folder structure to make iso CD
by Tanktalus (Canon) on Apr 04, 2006 at 19:43 UTC

    I do exactly the same thing, using proprietary code (sorry, can't share it). However, I use some key non-proprietary code which I can point you to: Filesys::DiskUsage to determine the size of a directory. Note that sector sizes on CDs are generally 1024 bytes, which doesn't match what du will tell you, but Filesys::DiskUsage can take parameters that allow you to specify what blocksize to assume.

    For my case, I need directories to show up on the CD in a particular order, which means that if dir5 can fit on disk1, but dir4 can't, then I can't put dir5 on disk1 in dir4's place. That may not be true for you. For me, it means that I may use more CDs, but I avoid the knapsack problem. You may need to look that problem up if you want to minimise the number of CDs that you need.

    If you are minimising, all you need to do is use Filesys::DiskUsage to get the sizes of each directory, then you can sort the directories in memory using those numbers until you get your solution. Then you can copy the directories around - I often use tar for copying directory structures which makes things much easier when you're dealing with many files, especially if some are symlinks and the like.

Re: Split file/folder structure to make iso CD
by pajout (Curate) on Apr 04, 2006 at 15:03 UTC
    It is, imho, more bashish than perlish question :>)
    I recommend to tar it and split it, if you have a lot of disk space...
    Update: Sorry, I'v ignored your condition.