[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: Coverting File Case



Hi

The only problem with the program you sent, is that files with
spaces in there name do not get processed. The for/in
command is to blame.

This is how I would do it:

---cut---
#!/bin/sh
# /usr/local/bin/lowerfiles
# chmod 755
# This will convert all files to lowercase showing the files being
# processed. If there is a file already named the same it will
# interactily ask if you wish to overwrite the file or not.
# Acceptable characters :
#  a-zA-Z'0-9{}[]()*&^%$#@|\:;,.<>?
# Spaces " " are changed to underscores "_".
# Unacceptable characters :
#  !/"` and probably TAB NL CR as well.
#start
ls -1 | \
 sed -e "s,.*, \
  if  [ -f \"&\" -a \
   \"&\" != \"\`echo \\\"&\\\" | tr [A-Z\\\ ] [a-z_]\`\" ] ; \
  then \
    mv -vi \"&\" \"\`echo \\\"&\\\" | tr [A-Z\\\ ] [a-z_]\`\" ; \
  fi," | \
 bash
#end
---cut---

Here is a test command:

---cut---
#!/bin/bash
# ./test
# chmod 755
# command to test /usr/local/bin/lowerfiles
#start
mkdir test-lower
cd test-lower
touch Cap "~d<K>d\'f?k-b|8\4" UP low "Sp ace"
touch "}w{k]S[e)j(g*t^8%9$e#w r+D=F:F&D;G,M"
echo - -----ls----- -
ls
echo - -lowerfiles- -
lowerfiles
echo - -----ls----- -
ls
echo - ----done---- -
cd ..
rm -r test-lower
#end
---cut---

Demo output:

---cut---
- -----ls----- -
Cap
~d<K>d\'f?k-b|8\4
low
Sp ace
UP
}w{k]S[e)j(g*t^8%9#w r+D=F:F&D;G,M
- -lowerfiles- -
`Cap' -> `cap'
`~d<K>d\\\'f?k-b|8\\4' -> `~d<k>d\\\'f?k-b|8\\4'
`Sp ace' -> `sp ace'
`UP' -> `up'
`}w{k]S[e)j(g*t^8%9#w r+D=F:F&D;G,M' -> `}w{k]s[e)j(g*t^8%9#w r+d=f:f&d;g,m'
- -----ls----- -
cap
~d<k>d\'f?k-b|8\4
low
sp_ace
up
}w{k]s[e)j(g*t^8%9#w r+d=f:f&d;g,m
- ----done---- -
---cut---

Guy



dTd wrote:
...snip...
MS> JW> I was wondering if there is a way to convert all the files in
MS> JW> a directory to a different case. I need all the files in a
MS> JW> certain dir to be lower case. I know the "tr" command lets you
MS> JW> convert lines in a file but i have not found a way to change
MS> JW> the file name itself.
...snip...

MS> tolower

Sorry, not very helpful, I know. Use this pointer:

http://freshmeat.net/projects/fixdos

use this little script in the directory:


#!/bin/sh
# lowerit
# convert all file names in the current directory to lower case
# only operates on plain files--does not change the name of directories
# will ask for verification before overwriting an existing file
for x in `ls`
do
if [ ! -f $x ]; then
continue
fi
lc=`echo $x | tr '[A-Z]' '[a-z]'`
if [ $lc != $x ]; then
mv -i $x $lc
fi
done







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]