[CLUE-Tech] removing spaces from filenames?
Keith Hellman
kehellman at yahoo.com
Sun Nov 17 15:42:17 MST 2002
On Sun, Nov 17, 2002 at 01:14:22PM -0700, Dave Price wrote:
> I have a _bunch_ of files that were created on a windoze system with
> embedded spaces in their names. Can anyone recommend a technique to
> programmatically rename the files - replacing ' ' with '_' on both the
> file and dir names?
The attached shell script works for me; it pumps out commands to stdout
so you can see what would happen first...
$cd LOTS_OF_WHITESPACE_TREE
$remove_ws_tree
<< review output >>
$remove_ws_tree |sh
--
Keith Hellman #include <disclaimer.h>
kehellman at yahoo.com from disclaimer import standard
"Before you critize someone, run a mile in their shoes. When you do
critize them, you'll be a mile away and you'll have their shoes."
--Unknown
-------------- next part --------------
#!/bin/bash
function nows()
{
D=$(dirname "$1")
B=$(basename "$1")
N="${B// /_}"
if test "$B" != "$N" ; then
echo "( cd '$D' && mv " "'$B'" "'$N' )"
fi
}
case "$1" in
file )
nows "$2"
;;
dir )
# rename all entries
find "$2" -mindepth 1 -maxdepth 1 -exec ${0} file '{}' \;
;;
"" )
find ./ -depth -type d -exec ${0} dir '{}' \;
;;
esac
More information about the clue-tech
mailing list