I'll be your Good Samaritan. First, let's cleanup your post.

Dear Monks:

I'm running into a fairly simple problem, but I have not been able to solve it. I have decided to look for some help. I'm not very good at scripting, and I was hoping that I would find a Good Samaritan on this website.

I have files in the following format:

/test1/da/0/1/nnn.dat /test1/da/0/2/nnn.dat /test1/da/0/3/nnn.dat /test1/da/y/n/nnn.dat /test1/da/y+1/n+1/nnn.dat /test1/da/y+1/n+2/nnn.dat /test1/da/y+n/n+n/nnn.dat

I want to copy all nnn.dat files that are located in every subfolder into a /newfolder/nnn.dat in such a way that each nnn.dat gets renamed according to its location.

For example:
/newfolder/0_1_nnn.dat /newfolder/0_2_nnn.dat /newfolder/0_3_nnn.dat /newfolder/y_n_nnn.dat

I don't know where to start. What would be a good starting point? Thank you for your help.

===============================================================

How did you do that?

For "Dear Monks:", I wrapped the expression in paragraph and italic tags:
<p><i>Dear Monks</i></p>
For each paragraph, use tags like this:
<p>I'm running into a fairly simple problem but I have not been able t +o solve it. I have decided to look for some help. I'm not very good a +t scripting , and I was hoping I would find a Good Samaritan on this +website.</p>
For your list of files, I wrapped the paths with code tags.
<code> /test1/da/0/1/nnn.dat /test1/da/0/2/nnn.dat /test1/da/0/3/nnn.dat /test1/da/y/n/nnn.dat /test1/da/y+1/n+1/nnn.dat /test1/da/y+1/n+2/nnn.dat /test1/da/y+n/n+n/nnn.dat </code>
Looking good... Now what? You'll need to follow Grandfather's advice and try to put a script together. You can start by studying the documentation for:

glob
rename
File::Copy
File::GlobMapper

Also, read and reread Writeup Formatting Tips

Now it's up to you. Good luck and keep trying!


In reply to Re: copy and rename depending on location by Khen1950fx
in thread copy and rename depending on location by oolmos

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.