CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Change the name of files dynamically

 



yasdel
Novice

Sep 27, 2010, 9:37 AM

Post #1 of 2 (434 views)
Change the name of files dynamically Can't Post

Hi Guys.

I am going to use a perl script that searches for .wma files in the specified directory and changes their audio properties. The problem I have is how to change name of each file dynamically. Let's say if :

original file => file1.wma
converted file => file1_cnvrt.wma

The command sox is used for this purpose and has this notation :

$cmd="sox $file -r $Fs file1.wma file1_cnvrt.wma"

my code is here. I simply need a suggestion for ??? in the code. I would appreciate if you could suggest the simplest possibility that can be understandable for me too. Thanks in advance.

my code :


Code
 
$dirtoget="/tsi/hadrien/deldjoo/Desktop/Ads/Sony_Serie_E_BALADEURS_Multimedia";
opendir(IMD, $dirtoget) || die("Cannot open directory");
@thefiles= readdir(IMD);
closedir(IMD);

$Fs=16000; # [Hz]
foreach $file (@thefiles){

if ($file=~m/.+\.wav/){ # $file=~m/.+\.wma/ gives true or false dependig if $file matches the pattern /.+\.wav/
$cmd="sox $file -r $Fs $file ????"
system($cmd); # here the command is called by the system
}
else {print "OK \n";}

}


My best,
YAS



(This post was edited by yasdel on Sep 27, 2010, 10:01 AM)


BillKSmith
Veteran

Sep 27, 2010, 11:21 AM

Post #2 of 2 (424 views)
Re: [yasdel] Change the name of files dynamically [In reply to] Can't Post

Copy your $file variable and change the '.' to '_cnvrt.' in the copy.


Code
use strict; 
use warnings;
my $Fs = 'Fs'; #On you own for this one!
my $file = 'file1.wma';
my $cnvrt_file = $file;
$cnvrt_file =~ s/\./_cnvrt./;
my $cmd = "sox $file -r $Fs $file $cnvrt_file";
print $cmd;

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives