braswell has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use DBI; use File::Find (); use vars qw/*name *dir *prune/; *name = *File::Find::name; *dir = *File::Find::dir; *prune = *File::Find::prune; my $dbh = DBI->connect("DBI:mysql:host=unixhost:database=fsdb", "username", "password"); my $sth = $dbh->prepare("INSERT INTO fstree (uid,size,mtime,name,lft,r +gt) VALUES(?,?,?,?,?,?)"); my $cnt = 1; my @stack; my $rowcnt; my $fs2probe = shift || die "supply a filesystem path to probe"; # Traverse desired filesystems File::Find::find({wanted => \&wanted, preprocess => \&pre, postprocess + => \&post}, $fs2probe); print "$rowcnt rows processed\n"; exit; sub wanted { my ($dev,undef,undef,undef,$uid,$gid, undef,$size,undef,$mtime) = lstat($_); if ( !($File::Find::prune |= ($dev != $File::Find::topdev)) ) +{ $rowcnt += $sth->execute($uid,$size,$mtime,$_,$cnt++,$ +cnt++) unless ( -d _ ); } } sub pre { push (@stack, [$_,$cnt++]); return @_; } sub post { my ($dev,undef,undef,undef,$uid,$gid, undef,$size,undef,$mtime) = lstat($name); my $ref = pop (@stack); $rowcnt += $sth->execute($uid,$size,$mtime,$ref->[0],$ref->[1] +,$cnt++); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using File::Find to build a Nested-Set Tree representation
by braswell (Sexton) on May 15, 2003 at 20:03 UTC | |
by braswell (Sexton) on Nov 10, 2003 at 21:12 UTC |