It looks like you may be trying to "rename" the file to a new directory. Are you sure that the new directory has been created at the point where the "rename" is being done?

Apart from that, it might make more sense to set this process up as a "filter" that will create a new set of files, rather than as an "in-place edit" that will relocate and then modify the files.

(The filter approach just seems safer -- if you find problems with what the program does, just fix it and run it again, because the original files that it used as input the first time are still where they used to be, and will still have the same contents they originally had, when you run it again.)

To summarize (in pseudo-perl):

locate the source directory and get the list of files there establish the name of the destination directory, and create it if nec +essary if $source_dir has subdirectories { create them as needed in the $dest_dir } for $infile ( @sourc_files ) { $outfile = $infile; $outfile =~ s{$source}{$dest}; # might be unnecessary? open(IN,"<","$source_dir/$infile"); open(OUT, ">","$dest_dir/$outfile"); while (<IN>) { s/$source/$dest/g; print OUT; } close IN; close OUT; }
It shouldn't need to be any more complicated than that (except maybe the initial part of finding the files and subdirectories, but I gather you already solved that part).

In reply to Re: Problem with Renaming script by graff
in thread Problem with Renaming script by kirk123

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.