NoobCoder has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Copy renaming trouble
by hippo (Archbishop) on Jun 14, 2016 at 22:20 UTC | |
by stevieb (Canon) on Jun 14, 2016 at 23:00 UTC | |
|
Re: File::Copy renaming trouble
by stevieb (Canon) on Jun 14, 2016 at 22:59 UTC |