Click to See Complete Forum and Search --> : Renamescript
superior88
01-04-2005, 09:11 PM
I'm trying to sort out my mp3dir. all dirs are in lowercase but i want first cap to be upper after every underscore '_'.
Can someone please help. I have tried to do it, and read the bash manual but i can't get it to work.
Help thx.
Icarus
01-04-2005, 11:17 PM
Could you provide a couple examples?
flukshun
01-05-2005, 03:33 AM
#!/usr/bin/perl
for (`ls -F`) {
next unless (m@/$@);
chomp(my $orig_dir = $_);
chop $orig_dir;
my @parts = split(/_/,$orig_dir);
for (@parts) {
$_ =~ /^(.)(.*)/;
$first_letter = $1;
$other_letters = $2;
$_ = uc($first_letter).$other_letters;
}
my $new_dir = join("_",@parts);
rename($orig_dir,$new_dir);
print "$orig_dir -> $new_dir\n" unless ($new_dir eq $orig_dir);
}
ugly, but it works as far as i can tell.
is there an easier way to list directories only?
superior88
01-05-2005, 07:24 AM
Originally posted by Icarus
Could you provide a couple examples?
Yes i meant like this.
this_is_a_test -> This_Is_A_Test.
And thanks flukshun it works fine :)
superior88
01-05-2005, 10:06 AM
Originally posted by flukshun
#!/usr/bin/perl
for (`ls -F`) {
next unless (m@/$@);
chomp(my $orig_dir = $_);
chop $orig_dir;
my @parts = split(/_/,$orig_dir);
for (@parts) {
$_ =~ /^(.)(.*)/;
$first_letter = $1;
$other_letters = $2;
$_ = uc($first_letter).$other_letters;
}
my $new_dir = join("_",@parts);
rename($orig_dir,$new_dir);
print "$orig_dir -> $new_dir\n" unless ($new_dir eq $orig_dir);
}
ugly, but it works as far as i can tell.
is there an easier way to list directories only?
Sorry i have to ask again.
I see now that i need it for files also, wich i figured out myself. but how to make it resursive?
and also make it uppecase after '-'. I hope it's not to much trouble.