Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
Neil Bradshaw wrote:
>
> Hey everyone,
>
> I had a final last night and my mind is fried. If anyone has a good idea
> as to how I should go about renaming a lot of files and folders, I'm all
> ears.
>
> Basically, I have a ton of files and folders that have uppercase
> characters as well as spaces. I have to recursively change all the
> uppercase letters to lowercase, and change all the spaces to
> underscores. I also need to output each filename with its complete path on
> one line into a file so that I have a long list of all the renamed files.
>
> Anyone know how I should tackle this? I'm thinking Perl...
>
Since the directories can change their name, it can be a bit tricky.
I came up with this. cd to the appropriate directory, then run this
script.
#!/usr/bin/perl -w
open F,"find -d . |";
while (<F>) {
chomp;
if (/(.*)\/(.*)/) {
$dir=lc($1);
$file=lc($2);
$file=~s/\ /\_/g;
$dir=~s/\ /\\\ /g;
s/\ /\\\ /g;
system "mv $_ $dir/$file\n";
}
}
--
Stephen Montgomery-Smith
EMAIL:PROTECTED
http://www.math.missouri.edu/~stephen
--
To unsubscribe, go to http://mlug.missouri.edu/members/edit.php
Archives are available at http://mlug.missouri.edu/list-archives/