Here is a sample of (windows) code that recursively reads starting from a start directory, and saves all the file information in a table format using native perl data structures. Here we use File::Find; File::Basename; and Data::Dumper to do all the heavy lifting.
### begin_: file metadata ### <region-file_info> ### main: ### - name : recursive search ### desc : recursively search thru directories and return t +he result in an array ref ### </region-file_info> ### begin_: init perl use strict; use warnings; use File::Basename; use File::Find; use Data::Dumper; ### begin_: init variables my $sSTartDir = "d:\\docs\\webpics"; my $oDirListing = (dirTreeToRsArray($sSTartDir) || "blank"); ### begin_: print the results print "\n"; use Data::Dumper; print Data::Dumper->Dump([$oDirListing], [qw(dataroot)]); ### begin_: function docs ### <region-function_docs> ### main: ### - name : dirTreeToRsArray($startdir) ### desc : | ### recurse all folders and files under start ### directory and return a rsArray (aka SimpleTable) ### usage : my $oDirListing = dirTreeToRsArray($startdir); ### return_value: ### - vartype : array ref (aka SimpleTable) ### desc : SimpleTable with a record for each item ### body : | ### The fields returned are: ### {name ="" ,path="" ,dir="" ,type="" ,depth="" ,relpa +th="", size="" ### ,startdir="" ,target=""} ### </region-function_docs> sub dirTreeToRsArray{ my ($startdir) = @_; my @outArray = (); my $recNum = 0; if($startdir){ $startdir =~ s!(\\)!/!igm; # normalize to unix-style pathste +ps }else{ die "missing required parameter"; } &find( sub { my @suffixlist = qw( \..* ); my ($basename,$path,$extension) = File::Basename::filepars +e($File::Find::name,@suffixlist); ### INIT my $sTemp = $File::Find::name; my $pathsteps = ''; my $outrec = {}; $outrec->{name} = "$basename$extension"; $outrec->{basename} = "$basename"; $outrec->{extension} = "$extension"; $outrec->{path} = "$File::Find::name"; $outrec->{dir} = "$path"; $outrec->{type} = (-f "$outrec->{path}")? "fil +e" : "dir"; $outrec->{size} = -s "$File::Find::name"; my @pathsteps = (split m!/!,$outrec->{path}) +; $outrec->{depth} = scalar @pathsteps; #$outrec->{relpath} = $sTemp; $outrec->{startdir} = $startdir; push @outArray, $outrec; } ,$startdir ); return \@outArray; }###end_sub
HTH.
In reply to Re: help with search script
by dimar
in thread help with search script
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |