Hi, You've got the basic idea correct. I also wrote some perl to perform a similar function. I also played loose with the rules by making use of global vars to store the matches. Here's my complete code:

#!/usr/bin/perl ######### # # index.pl # # script to create a static HTML file listing all pdfs down # from a particular directory and provide links to them. use Template; use File::Find; use File::Basename; # Template Files my $tmpl_dir = "/export/home/fredk/docs/index/templates"; my $output_tmpl = "$tmpl_dir/pdf.tmpl"; # Name of Output file $outputFile = "pdfs.html"; # Declarations my @list; # Extract the path to this script my $dir = dirname($0); if ( $ARGV[0] ) { $dir = $ARGV[0]; } # OR, override it by the cmd lin +e # What to search for CURRENTly hard coded #my $regex = '.*\.html$'; my $regex = '.*\.pdf$'; # Create a list "@list" containing the path of the pdfs &find(\&wanted, $dir); # # Output HTML my $vars = { # change to be appro. for the form 'list' => \@list, }; my $template = Template->new(); $template->process( $output_tmpl, $vars, $outputFile) || &error( $template->error()) ; exit; ##################################### # # The wanted() function does whatever verifications you want. # $File::Find::dir contains the current directory name, and $_ # the current filename within that directory. # $File::Find::name contains "$File::Find::dir/$_". You are # chdir()'d to $File::Find::dir when the function is called. # The function may set $File::Find::prune to prune the tree. sub wanted { if ( /$regex/ ) { push( @list, $File::Find::name); } }

In reply to Re: Using File::Find to Create a List of Files by freddo411
in thread Using File::Find to Create a List of Files by svsingh

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.