using perl to check modified date and then move to a folder

I am looking for a perl script that i can check the modfied date and then if its older than 6mos move into an archive folder.
nexcoolAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
for( <*> ){
    rename $_,"/archive/$_" or warn "/archive/$_ $!" if -f && -M > 6*30;
}
0
 
ps15Commented:
does it need to be perl ?
a simple shell command would be more easy:

find /dir/to/search -atime 180 -exec mv {}  /other/dir \;
0
 
ps15Commented:
or, if you want it recursive and with perl (re-using ozo's code),
perl -MFile::Find -e 'find(sub {$_=$File::Find::name;rename $_,$ARGV[1].$_ or warn $ARGV[1]."$_ $!" if -f && -M > 6*30;},$ARGV[0])' /dir/to/search/ /dir/to/move/to/
0
 
TintinCommented:
ps15.

-atime should be -mtime
0
 
ps15Commented:
Tintin,

Ah right, thanks =)
0
All Courses

From novice to tech pro — start learning today.