writing newfile to a dir

2005-01-17 Thread Brian Volk
Hi All,
I created a script that renames a dir of MP3 files...  Everything is 
working well except when I try to write the new files to a directory.   
I thought I could print to a dirhandle, apparently not.. :~)  Maybe I 
need to mv the $newfile...?  not sure... Any help would be greatly 
appreciated!

Thanks! 

Brian
#!/usr/bin/perl
use strict;
use warnings;
my $mp3_dir = /home/bvolk/Dell/Shared/Mp3_to_wav;
opendir (FILES, $mp3_dir) || die Couldn't open $mp3_dir: $! \n;
my @files = grep { !/^\.\.?$/ } readdir FILES;
closedir FILES;
my $new_mp3_dir = /home/bvolk/Music/MP3_files;
opendir (NEWDIR, $new_mp3_dir) || die Couldn't open $new_mp3_dir: $! \n;
foreach my $file(@files){
   my($newfile) = lc $file;   # Lower case all file names
   $newfile =~ s/ /_/g;   # Replace spaces w/ underscores
   $newfile =~ s//and/g; # Replace ampersands
   $newfile =~ s/\'//g;   # Remove apostrophes
   $newfile =~ s/(\(|\))//g;  # Remove parenthesis
   $newfile =~ s/[\-]//g; # Remove dashes
   $newfile =~ s/,//g;# Remove commas
  
   print NEWDIR $newfile \n;
}

closedir NEWDIR;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: writing newfile to a dir

2005-01-17 Thread JupiterHost.Net

Brian Volk wrote:
Hi All,
Hello,
I created a script that renames a dir of MP3 files...  Everything is 
Perhaps File::Copy::Recursive can assist you in this?
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.02/Recursive.pm
use File::Copy::Recursive 'dircopy';
dircopy($orig,$new) or die Copying $orig failed: $!;
unlink $orig or die Removing $orig failed: $!;
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: writing newfile to a dir

2005-01-17 Thread Brian Volk
JupiterHost.Net wrote:

Brian Volk wrote:
Hi All,

Hello,
I created a script that renames a dir of MP3 files... Everything is 

Perhaps File::Copy::Recursive can assist you in this?
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.02/Recursive.pm
use File::Copy::Recursive 'dircopy';
dircopy($orig,$new) or die Copying $orig failed: $!;
unlink $orig or die Removing $orig failed: $!;
HTH :)
Lee.M - JupiterHost.Net
Lee,
Thanks for the help... I used rename and it worked great. I will 
definitely check out your suggestion as well.. Thanks again...
rename $mp3_dir/$file, $new_mp3_dir/$newfile;

Brian
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: writing newfile to a dir

2005-01-17 Thread JupiterHost.Net

Brian Volk wrote:
JupiterHost.Net wrote:
Brian Volk wrote:
Hi All,

Hello,
I created a script that renames a dir of MP3 files... Everything is 

Perhaps File::Copy::Recursive can assist you in this?
http://search.cpan.org/~dmuey/File-Copy-Recursive-0.02/Recursive.pm
use File::Copy::Recursive 'dircopy';
dircopy($orig,$new) or die Copying $orig failed: $!;
unlink $orig or die Removing $orig failed: $!;
HTH :)
Lee.M - JupiterHost.Net
Lee,
Thanks for the help... I used rename and it worked great. I will 
No problem :)
definitely check out your suggestion as well.. Thanks again...
rename $mp3_dir/$file, $new_mp3_dir/$newfile;
great, the reason it didn't work before was that to create new files you 
open() a file handle to do that, not write to a directory handle, if I 
may use that term to describe what was going on :)

perldoc -f open
perldoc -f opendir
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response