in reply to monitoring directory for new subdirectories
Another possibility...
#! /usr/local/bin/perl use strict; use warnings; use File::Find (); use List::Compare; use Tie::Persistent; my $root = shift or die "USAGE: $0 <directory>"; die "$root: not a directory" unless(-d $root); # Get historic and current states tie my @dirs, 'Tie::Persistent', './dirs.pd', 'rw'; my @newdirs = get_dirs($root); # Check for changes my $lc = List::Compare->new(\@dirs, \@newdirs); print "Removed directories:\n\t" . join("\n\t", $lc->get_unique()) . " +\n"; print "New directories:\n\t" . join("\n\t", $lc->get_complement()) . " +\n"; # Update the persistent record @dirs = @newdirs; exit(0); print "@dirs\n"; { my @dirs; sub wanted { my ($dev,$ino,$mode,$nlink,$uid,$gid); (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -d _ && push(@dirs, $File::Find::name); } sub get_dirs { my $root = shift; # Traverse desired filesystems File::Find::find({wanted => \&wanted}, $root); return(@dirs); } }
|
|---|