Archive for December, 2008

To find all mp3 in your directory and make winamp list

By bo, 4 December, 2008, No Comment

The problem was to make a list of all mp3 files in a directory. The solution was easy, if you use
perl File::Find module. You can also, as mentioned in other post here, use $ find2perl -name *.mp3 on the command line, but .. i would like to make also a playlist for my favorite mp3 player and defacto standard winamp. So here is the code, and hope this helps somebody :-) to solve his problem :-) … Comment are on .. Please drop a line. Thanks and regards.

#! /usr/bin/perl -w
use strict;
use File::Find ();
use Cwd;
my $cwd = getcwd();
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
my @files;
File::Find::find({wanted => \&wanted}, '.');
# Traverse desired filesystems
my $list=< [playlist]
NumberOfEntries=$#files
PLAYLIST
print $list;
my $i=0;
foreach my $file (@files) {
$i++;
printf ("File%s=%s",$i,$file);
}
exit;
sub wanted {
/^.*\.mp3\z/s && push (@files,sprintf("%s/%s\n",$cwd,$name));
}