Rename multiple files in subdirectories from uppercase, lower case or mixed case to Proper title case names
I often find large libraries of files specially Music collected from here and there and has names in various forms and specially when all in UPPERCASE it just fills up your player display and becomes annoying.
I have written a quick bash script to rename any file names in any level of subdirectories to the Proper title case so anything with "File Name.TXT" or FILE NAME.TXT" or "filE NaME.tXt" will simply be renamed to "File name.txt".
Simply copy paste below script in a script file and run the file in Linux bash console. If you are using Windows you can install Cygwin utility to provide you unix type access from your windows system.
#!/bin/bash
DIR="$1"
# failsafe - fall back to current directory
[ "$DIR" == "" ] && DIR="."
# save and change IFS
OLDIFS=$IFS
IFS=$'\n'
# read all file name into an array
fileArray=($(find $DIR -type f))
# restore it
IFS=$OLDIFS
# get length of an array
tLen=${#fileArray[@]}
# use for loop read all filenames and output what is being processed and renamed, or not
for (( i=0; i<${tLen}; i++ ));
do
file="${fileArray[$i]}"
echo Processing file $file
filename=${file##*/}
path=${file%/*}
name2="$(echo $filename | tr [:upper:] [:lower:])"
newname="$(echo $name2 | cut -c 1 | tr 'a-z' 'A-Z')${name2#?}"
if [ "$filename" = "$newname" ]
then
echo "--- "File name $filename already same as $newname
else
echo "+++ "Changing file $path/$filename to $path/$newname
mv "$path/$filename" "$path/$newname"
fi
done
I have written a quick bash script to rename any file names in any level of subdirectories to the Proper title case so anything with "File Name.TXT" or FILE NAME.TXT" or "filE NaME.tXt" will simply be renamed to "File name.txt".
Simply copy paste below script in a script file and run the file in Linux bash console. If you are using Windows you can install Cygwin utility to provide you unix type access from your windows system.
#!/bin/bash
DIR="$1"
# failsafe - fall back to current directory
[ "$DIR" == "" ] && DIR="."
# save and change IFS
OLDIFS=$IFS
IFS=$'\n'
# read all file name into an array
fileArray=($(find $DIR -type f))
# restore it
IFS=$OLDIFS
# get length of an array
tLen=${#fileArray[@]}
# use for loop read all filenames and output what is being processed and renamed, or not
for (( i=0; i<${tLen}; i++ ));
do
file="${fileArray[$i]}"
echo Processing file $file
filename=${file##*/}
path=${file%/*}
name2="$(echo $filename | tr [:upper:] [:lower:])"
newname="$(echo $name2 | cut -c 1 | tr 'a-z' 'A-Z')${name2#?}"
if [ "$filename" = "$newname" ]
then
echo "--- "File name $filename already same as $newname
else
echo "+++ "Changing file $path/$filename to $path/$newname
mv "$path/$filename" "$path/$newname"
fi
done