Quote:> This convert all filenames in a directory from upper- to lower-case:
> for file in *
> mv $file `echo $file |dd conv=lcase 2>/dev/null`
> Hope this helps.
> Randy Howard
One problem with all of these is that the don't address
the issue of some files being already in lowercase --
and especially they don't address the problem of name
Consider if I have:
... as my files.
Let's create a shell function for easy readability:
echo $(echo "$1" | tr [:upper:] [:lower:]
Now we can use something like:
for i in ./*[A-Z]* ; do
lname=$( lcase "$i" )
[ ! -f "$lname" ] && mv "$i" "$lname" \
|| echo "$i" collides with "$lname" >&2
... this only matches files with at least one uppercase letter,
it protects against filenames with spaces in them (by soft quoting
every variable reference) and it reports collisions on standard
error. By preceding the glob pattern with "./" I also protect
against problems with degenerate filenames (those starting with
"-" that cause some many users so much trouble).
It still isn't perfect. It doesn't check for write access
to the current directory -- and it may have other problems
that I haven't thought of, yet. However it does catch the
most likely problems.
The biggest problem with my sample is that it doesn't take
any parameters. I could name it "lower.all.names" -- but
I'd have to work on it a bit to actually handle an arbitrary
list of parameters in a robust way. It would probably double
the length of the script (at least).
Starshine Technical Services http://www.starshine.org
Key fingerprint = 2524E3FEF0922A84 A27BDEDB38EBB95A