Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: monitoring directory for new subdirectories

by ig (Vicar)
on Mar 29, 2009 at 00:14 UTC ( [id://753924]=note: print w/replies, xml ) Need Help??


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); } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://753924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2026-01-23 01:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (125 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.