I have been struggling with this for a few days now. Every time I think I have a workable algorithm for this I end up seeing a huge flaw. It screams recursive but I just can't seem to figure one out.

Here is the dataset:

Given a set of directories in this layout:

/data/client1/project_type_1/project_1
/data/client1/project_type_1/project_2
/data/client1/project_type_2/project_3
/data/client2/project_type_1/project_4
/data/client2/project_type_1/project_5
/data/client2/project_type_2/project_6
/data/client3/project_type_1/project_7
/data/client3/project_type_1/project_8
/data/client4/project_type_1/project_9
/data/client5/project_type_2/project_10
/data/client5/project_type_2/project_11

Where in subdirectories there is unstructured data in files that are in unstructured subdirectories under the "project_1" type level.

Where the largest file size is < 2 gb.

Where the total file size for a "project_1" like dir can be > 10 gig or < 50k

Where the "project_1" like field do not have to be named unique, but contain unique data and subdirectory structure.

Here is the problem:

Get a unique lists of files that when added up the total size is > 3.5 gig and less than 4.2 gig while keeping all of a "project_1" together in the same list of filenames unless it is >4.2 gig - at which point it should be broken up into as few lists as possible.

Example
<project> <total size>
/data/client1/project_type_1/project_1 200mb
/data/client1/project_type_1/project_2 3.1 gb
/data/client1/project_type_2/project_3 1.2gb
/data/client2/project_type_1/project_4 7.4gb
/data/client2/project_type_1/project_5 31mb
/data/client2/project_type_2/project_6 400mb
/data/client3/project_type_1/project_7 2.5 gb

The lists returned would be
1:
all of the files in
/data/client1/project_type_1/project_1
/data/client1/project_type_1/project_2
/data/client2/project_type_1/project_5
/data/client2/project_type_2/project_6

2:
/data/client1/project_type_2/project_3
/data/client3/project_type_1/project_7

3:
First 4.2 gigs of files in /data/client2/project_type_1/project_4

4:
Remaining files in /data/client2/project_type_1/project_4



I can't seem to figure out (even in pseudo code) how to do this. I think I am just fried from this project.

Anyone have any ideas? Need more info let me know...


Thanks!
Waswas

In reply to My brain hurts! Recursive directory algorithm.. by waswas-fng

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.