[Asterisk-Users] Playing GSM files(s)

Scott Stingel scott at evtmedia.com
Thu Feb 12 15:48:15 MST 2004


Try this Perl subroutine to get an alphabetic list of all files, excluding
the "dot" files, and excluding sub-directories:

use DirHandle;

sub justthefiles {
   my $dir = shift;
   my $dh = DirHandle->new($dir)   or die "can't opendir $dir: $!";
   return sort                     # sort pathnames
          grep {    -f     }       # choose only "plain" files
          map  { "$dir/$_" }       # create full paths
          grep {  !/^\./   }       # filter out dot files
          $dh->read();             # read all entries
}

---------------------------

Call it like:

# get the list of files to be processed:
my @dirlist = justthefiles($directoryname);   # reads into an array

---------------------------
Use like this:

for each $file (@dirlist) {
	blah blah;
}

Hope this helps!
Scott


Scott M. Stingel 
Emerging Voice Technology Inc.

Email:          scott at evtmedia.com <mailto:scott at evtmedia.com>   
URL:            www.evtmedia.com <http://www.evtmedia.com>   



-----Original Message-----
From: asterisk-users-admin at lists.digium.com
[mailto:asterisk-users-admin at lists.digium.com] On Behalf Of Juan Cardenas
Sent: Thursday, February 12, 2004 3:54 PM
To: Asterisk-Users at lists.digium.com
Subject: [Asterisk-Users] Playing GSM files(s)


I know this is not a perl user list but it has to do with something I'm
trying to get working with Asterisk. I'm trying to create an AGI script
that can play all files in a directory. Hopefully get it to the point
where the user can hit '2' to continue and 'anyotherkey' to exit.
This is what I have so far.... Any ideas?

#!/usr/bin/perl

use Asterisk::AGI;

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();
my $directory = '/var/lib/asterisk/test';
my $file =0;

{
opendir(DIR, $directory) || die "can't opendir $directory: $!";
foreach grep {/^msg} readdir(DIR) $file="$message";

close DIR;
}
print "STREAM FILE $message";


I know it's sloppy I need serious perl lessons, can anyone give some
advice?


_______________________________________________
Asterisk-Users mailing list
Asterisk-Users at lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users





More information about the asterisk-users mailing list