Quote:
Originally Posted by Bruce Hill
I searched "remove spaces" and "Chinaman" and found this script
IIRC...
|
This script almost worked for me but in nested directories with space in both the directory names and file names it failed to substitute for spaces in the deepest directory (all directory names where handled correctly and all file names in directories above the deepest level were also handled correctly). My work around was to comment out the j=$((j-1) line (see below).
#!/bin/bash
# This is RecursiveSpaceSustituter.sh
IFS='
'
j=`find $1 -printf "%d\n" | sort -u | tail -n 1`
#j=$((j-1))
echo "Max dir depth:" $j
for (( i=0; i<=j ; i++ ))
do
for name in `find -mindepth $i -maxdepth $i -iname "* *" -printf "%p\n"`
do
newname=`echo "$name" | tr " " "_"`
echo "$name" "$newname"
mv "$name" "$newname"
done
done
##########
My test tree was as follows:
~/F\ A/RecursiveSpaceSubstituter.sh
~/F\ A/1\ 1
~/F\ A/2\ 1
~/F\ A/3\ 1
~/F\ A/F\ B/1\ 2
~/F\ A/F\ B/2\ 2
~/F\ A/F\ B/3\ 2
~/F\ A/F\ B/F\ C/1\ 3
~/F\ A/F\ B/F\ C/2\ 3
~/F\ A/F\ B/F\ C/3\ 3
All file and directory names above were handled OK.
The three file names below were not changed by the original script.
~/F\ A/F\ B/F\ C/F\ D/1\ 4
~/F\ A/F\ B/F\ C/F\ D/2\ 4
~/F\ A/F\ B/F\ C/F\ D/3\ 4
I hope this helps somebody. I would love some feedback on this.
Best regards.