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 ;)In reply to Problem with renaming files in directory by ice_ice_ice
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |