Parsing Path Data into Tree Structure

Discussion in 'Perl Misc' started by Dale, Apr 30, 2004.

  1. Dale

    Dale Guest

    I'm creating a simple web-based image management tool and am looking
    for a way of creating a tree structure to display folders and titles
    of images contained in those folders. What I am trying to do is take a
    very plain text string describing a path and parse that into a tree to
    display in html.

    My incoming data via DBI looks like this

    /folder 1/image1.jpg
    /folder 1/subfolder 1/image2.jpg
    /folder 1/subfolder 1/subsub folder 1/image3.jpg
    /folder 1/image4.jpg
    /folder 2/image5.jpg
    /folder 1/subfolder 2/image6.jpg
    etc...

    and I want to output sort of like

    folder 1
    -> subfolder 1
    -> -> subsubfolder 1
    -> -> -> image3.jpg
    -> -> image2.jpg
    -> subfolder 2
    -> -> image6.jpg
    -> image1.jpg
    -> image4.jpg
    folder 2
    -> image5.jpg

    though with lots of pretty icons and collapsing row structures (which
    I won't bore you with since its jscript and not perl)

    So my questions:

    1. Is there a module available anywhere that already does this?
    2. If not, I can work with one of the Tree:: modules and need ideas on
    how to parse my paths into the required structure. (ie how to extract
    the parent/child node relationships correctly)
    3. And if there is another better way of accomplishing this whole task
    I would love to hear about it.

    * and for those list purists who are wondering where the perl is in
    this question, my whole app is perl, so am looking for perl answers
    using regexes, splits, and arrays or hashes, etc.

    Many thanks in advance for any guidance

    DRE
    Dale, Apr 30, 2004
    #1
    1. Advertising

  2. Dale <> wrote:

    > What I am trying
    > to do is take a very plain text string describing a path and parse
    > that into a tree to display in html.
    >
    > My incoming data via DBI looks like this
    >
    > /folder 1/image1.jpg
    > /folder 1/subfolder 1/image2.jpg
    > /folder 1/subfolder 1/subsub folder 1/image3.jpg
    > /folder 1/image4.jpg
    > /folder 2/image5.jpg
    > /folder 1/subfolder 2/image6.jpg
    > etc...
    >
    > and I want to output sort of like
    >
    > folder 1
    > -> subfolder 1
    > -> -> subsubfolder 1
    > -> -> -> image3.jpg
    > -> -> image2.jpg
    > -> subfolder 2
    > -> -> image6.jpg
    > -> image1.jpg
    > -> image4.jpg
    > folder 2
    > -> image5.jpg



    Search Google groups for Message-ID
    <> and you'll find an
    algorithm you can adapt.
    David K. Wall, Apr 30, 2004
    #2
    1. Advertising

  3. David K. Wall <> wrote:
    > Dale <> wrote:
    >
    >> What I am trying
    >> to do is take a very plain text string describing a path and parse
    >> that into a tree to display in html.



    > Search Google groups for Message-ID
    ><> and you'll find an
    > algorithm you can adapt.



    Or adapt this shell one-liner (good luck!). :)


    find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,| ,g'


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Apr 30, 2004
    #3
  4. Dale

    Dale Guest

    Thanks. Will give this a shot.

    DRE

    Tad McClellan <> wrote in message news:<>...
    > David K. Wall <> wrote:
    > > Dale <> wrote:
    > >
    > >> What I am trying
    > >> to do is take a very plain text string describing a path and parse
    > >> that into a tree to display in html.

    >
    >
    > > Search Google groups for Message-ID
    > ><> and you'll find an
    > > algorithm you can adapt.

    >
    >
    > Or adapt this shell one-liner (good luck!). :)
    >
    >
    > find . -print | sed -e 's,[^/]*/\([^/]*\)$,`--\1,' -e 's,[^/]*/,| ,g'
    Dale, May 1, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stub

    B tree, B+ tree and B* tree

    Stub, Nov 12, 2003, in forum: C Programming
    Replies:
    3
    Views:
    10,091
  2. sharan
    Replies:
    4
    Views:
    675
    CBFalconer
    Oct 30, 2007
  3. sharan
    Replies:
    2
    Views:
    822
    SM Ryan
    Oct 31, 2007
  4. sharan
    Replies:
    1
    Views:
    679
    CBFalconer
    Oct 30, 2007
  5. Replies:
    1
    Views:
    1,079
    Ian Collins
    Apr 11, 2008
Loading...

Share This Page