Skip to content

Commit

Permalink
add script
Browse files Browse the repository at this point in the history
  • Loading branch information
miyagawa committed Oct 24, 2012
1 parent 94d686d commit 9858516
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions folder-watcher/find-and-symlink.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/perl
use strict;
use File::Find;

my $now = time;

my($watch, $linkdir, $age) = @ARGV;
$age ||= 3600 * 24 * 30;
mkdir $linkdir, 0777 unless -e $linkdir;

my %exists = map { ($_ => 1) } glob "$linkdir/*";

find(\&want, $watch);

for my $e (keys %exists) {
unlink $e;
}

sub want {
/\.(?:avi|mp4|divx|m4v|mov|mkv|flv|wmv)$/i or return;
my @stat = stat($File::Find::name);
if ($now - $stat[9] < $age) {
my $link = "$linkdir/$_";
if ($exists{$link}) {
delete $exists{$link};
} else {
symlink $File::Find::name, $link;
}
}
}

0 comments on commit 9858516

Please sign in to comment.