[CLUE-Tech] removing spaces from filenames?
David Anselmi
anselmi at americanisp.net
Mon Nov 18 16:18:36 MST 2002
Warren Raquel wrote:
> Here's a short shell script that you can run inside the directory to
> take care of all spaces. It should convert all files and directory names
> with spaces.
Well, shoot. Since globbing seems to work better than find in a for
loop, here's a recursive version:
>8-----cut here------>8
#!/bin/sh
for i in * ; do
NEW=`echo $i| sed 's/ /_/g'`
if [ "$i" != "${NEW}" ]
then
(cd "$i" 2>/dev/null && $0)
mv "$i" "${NEW}"
echo "$i converted to ${NEW}"
else
echo 'The name is the same'
fi
done>8-----cut here------>8
The script has to be called with an absolute path, or it must be in your
path. I suppose testing that $i is a directory may be safer than just
cd'ing to it (though the if then above isn't really necessary the same way).
Dave
More information about the clue-tech
mailing list