pbaumgar has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use File::stat; use POSIX qw(strftime); my $maillog_dir = '/var/log/maillogs'; opendir ( LOG, $maillog_dir) or die ("Can't open $maillog_dir: $!"); my @list = sort { -M "$maillog_dir/$a" <=> -M "$maillog_dir/$b" } grep { -f "$maillog_dir/$_" } readdir ( LOG ); foreach my $file ( @list ){ my $datestamp = strftime("%Y%m%d", localtime(stat("$maillog_di +r/$file")->mtime)); $file =~ s/\d+/$datestamp/; print "$file\n"; } close ( LOG );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: rename files with mtime
by GrandFather (Saint) on Feb 14, 2009 at 20:00 UTC | |
|
Re: rename files with mtime
by CountZero (Bishop) on Feb 14, 2009 at 20:53 UTC | |
|
Re: rename files with mtime
by Narveson (Chaplain) on Feb 15, 2009 at 03:56 UTC | |
by grinder (Bishop) on Feb 15, 2009 at 10:00 UTC | |
|
Re: rename files with mtime
by oko1 (Deacon) on Feb 15, 2009 at 20:23 UTC |