35 $destdir = $dir->child($destdir) if $destdir->is_relative; |
35 $destdir = $dir->child($destdir) if $destdir->is_relative; |
36 my $destfmt = ($opt->subdir eq 'month') ? '%Y-%m' : '%Y'; |
36 my $destfmt = ($opt->subdir eq 'month') ? '%Y-%m' : '%Y'; |
37 my $nowish = time; |
37 my $nowish = time; |
38 my $age = $opt->age * 24 * 60 * 60; |
38 my $age = $opt->age * 24 * 60 * 60; |
39 |
39 |
|
40 my @work; |
|
41 |
40 for my $child ($dir->children) { |
42 for my $child ($dir->children) { |
41 next if $child->is_dir && ( |
43 next if $child->is_dir && ( |
42 $opt->files || $child eq $destdir || $child =~ /^(?:\d{4}|\d\d)$/ |
44 $opt->files || $child eq $destdir || $child =~ /^(?:\d{4}|\d\d)$/ |
43 ); |
45 ); |
44 next if $opt->files && $child->basename =~ /^\./; |
46 next if $opt->files && $child->basename =~ /^\./; |
45 |
47 |
46 my $mtime = $child->stat->mtime; |
48 my $mtime = $child->stat->mtime; |
47 next unless ($nowish - $mtime) >= $age; |
49 next unless ($nowish - $mtime) >= $age; |
48 |
50 |
49 my $dest = $destdir->child(localtime($mtime)->strftime($destfmt)); |
51 my $dest = $destdir->child(localtime($mtime)->strftime($destfmt)); |
|
52 push @work, [$dest, $child]; |
|
53 } |
50 |
54 |
51 print "$dest \t $child\n"; |
55 my $lastdest = ''; |
|
56 for my $work (sort {$a->[0] cmp $b->[0]} @work) { |
|
57 my ($dest, $child) = @$work; |
|
58 |
|
59 say $lastdest = $dest |
|
60 if $dest ne $lastdest; |
|
61 |
|
62 say "\t$child"; |
52 |
63 |
53 next unless $opt->yes; |
64 next unless $opt->yes; |
54 $dest->mkpath; |
65 $dest->mkpath; |
55 $child->move($dest . '/' . $child->relative($dir)); |
66 $child->move($dest . '/' . $child->relative($dir)); |
56 } |
67 } |