in reply to How do I read all files in a directory recursively?
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