in reply to Using File::Find to Create a List of Files
#!/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); } }
|
|---|