Is it possible to have a batch file that can rename filenames so that the first letter of every word is capitalised, and every other character is lower case, please?
For example, say you have the following files in a folder:
meat loaf_i would do anything for love but i won't do that.Mp3
meat loaf_it's all coming back.mp3
meat loaf_objects in the rear view mirror may appear closer.MP3
MEAT LOAF - IS NOTHING SACRED.mp3
mike oldfield - moonlight shadow.mp3
3 moody blues_i know you're out there somewhere.mp3
nick drake - northern sky.mp3
procol harum_A WHITER SHADE OF PALE.mp3
and you copy the batch file into that folder, and run it, and you end up with:
Meat Loaf_I Would Do Anything For Love But I Won't Do That.mp3
Meat Loaf_It's all coming back.mp3
Meat Loaf_Objects In The Rear View Mirror May Appear Closer T.mp3
Meatloaf - Is Nothing Sacred.mp3
Mike Oldfield - Moonlight Shadow.mp3
3 Moody Blues_I Know You're Out There Somewhere.mp3
Nick Drake - Northern Sky.mp3
Procol Harum_A Whiter Shade Of Pale.mp3
Also, if possible, could the same batch file convert the file extensions to all lower case, please?
Thanks for any answers.
How to rename filenames so only the first letter of words are capitalized?
Moderator: DosItHelp
Re: How to rename filenames so only the first letter of words are capitalized?
Hi
You can give a try for this batch script using a function in vbscript to capitalize each first letter in the word :
You can give a try for this batch script using a function in vbscript to capitalize each first letter in the word :
Code: Select all
@echo off
Title Capitalize The First Letter Of The Word by Hackoo 2020
Set Str="meat loaf_i would do anything for love but i won't do that.Mp3"^
#"meat loaf_it's all coming back.mp3"^
#"meat loaf_objects in the rear view mirror may appear closer.MP3"^
#"MEAT LOAF - IS NOTHING SACRED.mp3"^
#"mike oldfield - moonlight shadow.mp3"^
#"3 moody blues_i know you're out there somewhere.mp3"^
#"nick drake - northern sky.mp3"^
#"procol harum_A WHITER SHADE OF PALE.mp3"
@For /f "tokens=1-8 delims=#" %%a in ("%str%") do (
echo %%~a
echo %%~b
echo %%~c
echo %%~d
echo %%~e
echo %%~f
echo %%~g
echo %%~h
echo(
Pause
echo(
Call :Upcase_First_Letter "%%~a"
Call :Upcase_First_Letter "%%~b"
Call :Upcase_First_Letter "%%~c"
Call :Upcase_First_Letter "%%~d"
Call :Upcase_First_Letter "%%~e"
Call :Upcase_First_Letter "%%~f"
Call :Upcase_First_Letter "%%~g"
Call :Upcase_First_Letter "%%~h"
)
pause
Exit
::------------------------------------------------------------------
:Upcase_First_Letter
(
echo wscript.echo UpFirstLetter("%~1"^)
echo Function UpFirstLetter(str^)
echo ArrStr = Split(str,chr(32^)^)
echo For i=LBound(ArrStr^) To UBound(ArrStr^)
echo O = O ^& Ucase(Left(ArrStr(i^),1^)^) ^& LCase(Right(ArrStr(i^),Len(ArrStr(i^)^)-1^)^) ^& chr(32^)
echo Next
echo UpFirstLetter = Trim(O^)
echo End Function
)>"%tmp%\%~n0.vbs"
cscript //nologo "%tmp%\%~n0.vbs" "%~1"
If Exist "%tmp%\%~n0.vbs" Del "%tmp%\%~n0.vbs"
Exit /B
::------------------------------------------------------------------
Re: How to rename filenames so only the first letter of words are capitalized?
Brilliant! Thanks very much, mate.
Re: How to rename filenames so only the first letter of words are capitalized?
Assuming you are dealing with English, it is a simple 2 step process with JREN.BAT - a hybrid batch/JScript regular expression renaming utility.
First capitalize the first character of every "word". Then convert all extensions to lower case.
Since JREN is a batch script, you must use CALL JREN if you put the commands within your own batch script.
There are many options to explore - use JREN /? from the command line to get the built in help.
Dave Benham
First capitalize the first character of every "word". Then convert all extensions to lower case.
Code: Select all
jren "([a-zA-Z])([a-zA-Z']*)" "uc($1)+lc($2)" /j
jren "\.[^.]+$" "lc($0)" /j
There are many options to explore - use JREN /? from the command line to get the built in help.
Dave Benham
Re: How to rename filenames so only the first letter of words are capitalized?
That's great! Thanks Dbenham.
I wish all forums were as helpful and friendly as this one
I wish all forums were as helpful and friendly as this one