renaming *.wav.mp3 to *.mp3 only
Robin Laing
Robin.Laing at drdc-rddc.gc.ca
Thu Jun 9 14:21:24 UTC 2005
Antonio Olivares wrote:
> Dear folks,
> Sorry if this has been asked many times but I need
> your help. I need to rename some music files that I
> created using lame to simply file.mp3 instead of the
> file.wav.mp3 format that they are in. I copied a
> script from the internet but it did not work to encode
> mp3 and I modified it so that I could get some output
> and it came to *.wav.mp3
>
> Here's the script
> #!/bin/sh
> for i in *.[wW][aA][vV]; do
> lame "$i" "$i".mp3
> done
>
> The resultant mp3 files had the *.wav.mp3 as I do not
> know how to modify the results.
>
> Regards,
>
> Antonio
>
Years ago when I was really trying to learn perl I cam across this
little program in a perl book. I think it was an O'Reilly's book.
--------- Begin program.
#!/usr/bin/perl
#
# Usage: rename perlexpr [files]
($regexp = shift @ARGV) || die "Usage: rename perlexpr [filenames]\n";
if (!@ARGV) {
@ARGV = <STDIN>;
chomp(@ARGV);
}
foreach $_ (@ARGV) {
$old_name = $_;
eval $regexp;
die $@ if $@;
rename($old_name, $_) unless $old_name eq $_;
}
exit(0);
---------- End program.
It is a handy little renaming program that has alot of usage.
It uses perl rename (and all the features) to allow easy changes to
files or directories. Do be careful as there is no protection in this
code for overwriting files that exist.
I save it as file_rename.pl
I can rename a whole set of file or just selected files by a simple
command.
file_rename 's/.wav.mp3/.mp3/' *
I use it almost daily for processing downloads and other things.
If I have a directory where I want all the files in lowercase.
file_rename 'tr/A-Z/a-z/' *
Just thought I would pass it on as there are repeated questions on
renaming groups of files.
--
Robin Laing
More information about the fedora-list
mailing list