Hello Monks,

I am in need of some advice. I've been coding for a few weeks now and I'm stuck on a part of my project. My goal is to have my code search through the directory for particular log files and to have them copied to a new location.

the problem comes from the fact that these files (which reside in different folders) have the same name. When I have them copied to the new location it overwrites the previous files (Which the contents are not the same).

I was trying to implement a renaming scheme that allowed for these files to be renamed when found and then copied over, but when I execute the code it only copies the original name to the new location (Over writing the previous ones). No error codes to share and I've consulted CPAN and perldoc. Any suggestions would be greatly appreciated.

Here is a copy of my code:
use warnings; use strict; use File::Find; use File::Copy; my $DirDestination = 'C:\Users\rfencer\Desktop\Log Files'; my $count= 0; find( { wanted => \&findfiles, }, "\\\\lefatols\\Kye230700-E\\DAT98\\KT11442\\Usr\\Results500\\R54_Nx\\5 +BLC" ); sub findfiles{ @ARGV = glob('*.log'); if (@ARGV){ my @copy= @ARGV; foreach $_(@copy){ if($_=~/run/i){ ReName($_); # rename($_,$count); copy($_, $DirDestination) or die($!); $count+=1;}}} }; sub ReName{ my $oldfn= 'Run.log'; my $newfn= $oldfn."$count"; my $send= rename($oldfn, $newfn); } print $count;

In reply to File::Copy renaming trouble by NoobCoder

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.