-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_1.pl
72 lines (52 loc) · 1.36 KB
/
6_1.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#6_1
use File::Find;
use Time::Local;
sub gather_mtime_between {
my ($start, $end) = @_;
my (@files);
my $process = sub {
#print "File: $File::Find::name\n";
my @stat = lstat($File::Find::name);
#print "Stat: @stat\n";
unless (defined @stat) {
warn "Can't stat $File::Find::name: $!, skipping\n";
return;
}
my $timestamp = $stat[9];
#print "FileTS:$timestamp\n";
#print "Start:$start\n";
#print "Stop:$end\n";
push @files, {
'name' => $File::Find::name,
'stat' => \@stat,
} if $start < $timestamp && $timestamp < $end;
};
my $output = sub {
return @files;
};
return ($process, $output);
}
my $target_dow = 1;
my @starting_directories = (".");
my $seconds_per_day = 24 * 60 * 60;
my ($sec, $min, $hour, $day, $mon, $year, $dow) = localtime;
my $start = timelocal(0, 0, 0, $day, $mon, $year); # start of today
while ($dow != $target_dow) {
# Back up one day
$start -= $seconds_per_day;
$dow = 7 if --$dow < 0;
}
my $stop = $start + $seconds_per_day;
#print "Start, Stop: $start, $stop\n";
my ($gather, $yield) = gather_mtime_between($start, $stop);
#print "Gather: $gather\n";
#print "Yield: $yield\n";
find($gather, @starting_directories);
my @files = $yield->();
foreach my $file (@files) {
use Data::Dumper;
Dumper($file);
my $mtime = $file->{'stat'}[9];
my $when = localtime $mtime;
print "$when: $file->{'name'}\n";
}