ice_ice_ice has asked for the wisdom of the Perl Monks concerning the following question:
opendir(DIR, '.') || die "Couldn't opendir: $!\n"; foreach my $filename (reverse((grep /^sniffer/, readdir(DIR)))) { my $new_name = $filename; if($new_name =~ m/(\d+)/) { my $value = $1 +1; $new_name =~ s/.*/"sniffer$value\.log"/; } else { $new_name =~ s/.*/sniffer1.log/; } rename($filename, $new_name) unless $filename eq $new_name; close(DIR);
My aim is to increment number in files which begin "sniffer". In example: sniffer.log will be sniffer1.log, sniffer1.log will be sniffer2.log, etc. The oldest file (with the highest number) must be changed at the beginning - this is the reason of using reverse function in foreach loop.
Unfortunately I received this error:
Insecure dependency in rename while running with -T switch at ...
If anyone knows the solution of this problem or the easiest way how to increment files number ?
Thanks in advance ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with renaming files in directory
by Ratazong (Monsignor) on Jan 03, 2012 at 15:40 UTC | |
|
Re: Problem with renaming files in directory
by toolic (Bishop) on Jan 03, 2012 at 15:50 UTC | |
by ice_ice_ice (Initiate) on Jan 03, 2012 at 16:30 UTC | |
by toolic (Bishop) on Jan 03, 2012 at 16:42 UTC | |
by ice_ice_ice (Initiate) on Jan 03, 2012 at 21:00 UTC | |
by toolic (Bishop) on Jan 03, 2012 at 21:40 UTC | |
|