I just wrote a program that toes exactly what you want to do. First I opendir() the directory then I readdir() the directory into an array. Finally I used foreach $file (@files) to process each file at a time

The file I created scans a directory for mp3's and extracts their running time using MPEG::MP3Info

It doesn't recurse subdirectories but that shouldn't be too hard to impliment by checking file attributes for the directory value. (at least in Win32) <code> #!c:\perl\bin\perl.exe use MPEG::MP3Info; my $file; my $out = '>>playlist.txt'; open (OUTFILE, $out); # replace with the directory containing the fines you want # does not recurse subdirectries $directory = "D:\\"; opendir (DIRECTORY, $directory); #read the file names into an array @files = readdir(DIRECTORY); #extract data from each file foreach $file (@files) { #is the file an mp3 if ($file =~ /.mp3/) { #extract info from mp3 using MPEG::MP3Info my $info = get_mp3info("$directory$file"); #get minutes and seconds my $minutes = $info->{MM}; my $seconds = $info->{SS}; #if seconds = 0 to 9 if (($seconds =~ tr/0-9/0-9/) == 1) { #set seconds = 00 to 09 so they print correctly $seconds = join ("", "0", $seconds); } #remove .mp3 extention from file name and print along with time

In reply to RE: How do I read all files in a directory recursively? by Anonymous Monk
in thread How do I read all files in a directory recursively? 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.