simple bash script question
Joshua D. Abraham
jabra at ccs.neu.edu
Wed Jan 25 19:40:06 EST 2006
Why not something like this?
#!/usr/bin/perl
#rename.pl
use strict;
use warnings;
use File::Copy;
my $location;
my $oldext;
my $newext;
if (@ARGV == 2 or @ARGV == 3) {
$oldext = $ARGV[0];
$newext = $ARGV[1];
$location = defined $ARGV[2] ? $ARGV : "./";
}
else {
die "Usage: $0 [oldext newext [directory]]\n";
}
opendir(DIR, $location);
for (readdir(DIR)) {
if (/$oldext$/) {
my $newfile = $_;
$newfile =~ s/$oldext$/$newext/;
warn "Renaming file $_ to $newfile \n";
if (! -e $newfile){
move ($_, $newfile);
} else {
warn "File $newfile already exists ";
next;
}
}
}
closedir(DIR);
--Josh Abraham
On Wed, Jan 25, 2006 at 07:35:46PM -0500, Rajiv Aaron Manglani wrote:
> >I'm in the middle of moving a whole slew of mp3s/.oggs to my freshly
> >modded xbox, however i've run into the snag of the xbox filesystem
> >(fatx) not liking certain charaters/filename lengths i have on my
> >desktop.
> ...
> >any ideas? better ways to do this?
>
> http://detox.sourceforge.net/
>
> "Detox is a utility designed to clean up filenames. It replaces
> difficult to work with characters, such as spaces, with standard
> equivalents. It will also clean up filenames with UTF-8 or Latin-1
> (or CP-1252) characters in them." ... "It was originally a personal
> project, written a few years ago to clean up the names of MP3s ripped
> under Windows."
>
> eg:
>
> $ touch test\ \(1\).foo
> $ ls *foo
> test (1).foo
> $ detox -n *foo
> test (1).foo -> test-1-.foo
>
>
>
> _______________________________________________
> Discuss mailing list
> Discuss at blu.org
> http://olduvai.blu.org/mailman/listinfo/discuss
More information about the Discuss
mailing list