One approach:

  1. Trawl through the tree with one of the File::Find::* modules.
  2. Build up a hash, keyed on the filenames with values of array refs of the directory paths.
  3. When the trawl has finished, go through the hash, ignoring any value where the array ref has a single entry.
  4. Slurp in each file in the array ref, appending to a scalar, deleting each file after you have read it, bar the last where you save the content from the scalar.

Caveat 1: Depending on your hardware and the actual numbers involved you may hit memory constraints with this.

I am using Strawberry Perl on Windows 10 64bit

Caveat 2: Windows sometimes does some odd filesystem things so take care. (I am not an MS user so can't comment further)

I am a newb

Welcome! Are you new to programming or just to Perl? There is lots of documentation to help you out so do browse around and keep asking questions. Good luck and enjoy the journey.


In reply to Re: [newbie question] Appending txt files with same name in different subdirectories by hippo
in thread [newbie question] Appending txt files with same name in different subdirectories by Kgs

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.