Here is a handy script for stripping spaces from filenames in a directory and all of its subdirectories:
#!/bin/bash
function strip_spaces_from_files {
for i in *
do
newfilename=$(echo $i | tr -s ' ' | tr ' ' '_')
if [ -e "$newfilename" ]
then
echo "$newfilename does not contain any spaces"
else
echo "stripping spaces from $newfilename"
mv "$i" "$newfilename"
fi
done
}
INITIALDIR=$PWD
echo "Stripping spaces from current directory $INITIALDIR"
strip_spaces_from_files
echo "Stripping spaces from sub directories"
for subd in $(find ./ -type d)
do
strippingdot=$(echo "${subd}"|sed 's/^..//')
echo "switching to directory $INITIALDIR/$strippingdot"
cd $INITIALDIR/$strippingdot
echo "stripping spaces"
strip_spaces_from_files
echo "going back to initial directory $INITIALDIR"
cd $INITIALDIR/
done
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.