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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.