Hey All,

So I am trying to write a script to iterate over a set of files and run some commands. The directory/file structure is

Dir1/001.jpg Dir2/002.jpg Dir2/001.jpg Dir2/001.cr2

etc. Basically each folder will have files from 001.ext, ... , n.ext. I would like to iterate over the files and run a program on each of them to make a thumbnail. I, however, only want to run 1 time per file independent of the ext... e.g. I would like to know that 001 has a cr2 and a jpg, but only want to make one thumbnail.

Does this make sense?

Right now I am using File::Find::Rule; and then getting all cr2, jpg, etc.. within the directory.

What is the best way to do this?

This is my current script that I want to modify so it only prints one thumbnail per image (even if there is a JPEG and a RAW)

#!/usr/bin/perl # Install ffmpeg, ufraw, ImageMagick print "Thumnailer, pix2tn\n\n"; my $filename = 'index.html'; $start_dir = shift || '.'; use File::Find::Rule; # find all the .pm files in @INC my @files = File::Find::Rule->file() ->name( '*.jpg', '*.avi', '*.raw', '*.cr +2', '*.jpeg', '*.nef', '*.mov') ->in( @INC ); @nfiles = grep(!/AppleDouble/, @files); my $tnperrow=4; # thumbnails per row my $tnsize=200; # size of thumbnails my $tnquality=40; # quality of thumbnails [0..100] # use small thumbnails with poor quality to speed up your index-page if (-e $filename) { rename $filename, $filename.".bak"; print "I saved the old $filename as $filename.bak\n"; } open (PAGE, ">$filename") || die "Problem: Can't write to filename\n"; # create a directory for the thumbnails system ("mkdir tn") if (!-d "tn"); #system ("mkdir med") if (!-d "med"); # create the index page print PAGE qq* <html><head><title>$title</title></head> <body bgcolor=white><h1>$title</h1> <table cellspacing=10 width="100%"> *; my $counter=0; foreach $_ (@nfiles) { $in = $_; $out = $_; $out =~ s/\//-/g; $out =~ s/\.avi$/.jpg/g; $out =~ s/\.cr2/.jpg/g; $out =~ s/\.nef/.jpg/g; $out =~ s/\.mov/.jpg/g; print $in; if ($in =~ /\.avi$/) { system ('convert', '-resize', $tnsize."x".$tnsize, '-quality', $tn +quality, $in.'[1]', 'tn/'.$out) == 0 || die "Problems with convert: $?\n"; #system ('convert', '-geometry', $medsize."x".$medsize, '-qualit +y', $medquality, $in.'[1]', 'med/'.$out) == 0 #|| die "Problems with convert: $?\n"; } elsif ($in =~ /\.mov/) { system ('convert', '-resize', $tnsize."x".$tnsize, '-quality', $t +nquality, $in.'[1]', 'tn/'.$out) == 0 || die "Problems with convert: $?\n"; } else { system ('convert', '-resize', $tnsize."x".$tnsize, '-quality', $ +tnquality, $in, 'tn/'.$out) == 0 || die "Problems with convert: $?\n"; } print PAGE "<tr valign=bottom>" if (!($counter++%$tnperrow)); print PAGE "<td>"; #<a href="med/$out"><img src="tn/$out" alt="click to enlarge"></a> +<br> @stat = stat $_; print PAGE qq*<center> <img src="tn/$out" alt="click to enlarge"><br>*; if ($in =~ /\.avi$/) { print PAGE "<b>AVI</b><br>"; } elsif ($in =~ /\.mov/) { print PAGE "<b>MOV</b><br>"; } elsif ($in =~ /\.cr2/) { print PAGE "<b>CR2 (RAW)</b><br>"; } elsif ($in =~ /\.jpg/) { print PAGE "<b>JPG</b><br>"; } print PAGE qq* <small><b>$_</b><br>*. localtime($stat[9]).<br>. qq*</small>\n*; print " ... done\n"; } print PAGE qq* </table><hr> Index created on *. localtime(time) .qq* </body></html> *; close PAGE; exit;

In reply to Iterate Recursively Through Directories by efaden

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.