JSI Tip 8379. How do I convert a file name to lowercase?

Jerold Schulman

August 15, 2004

1 Min Read
ITPro Today logo in a gray background | ITPro Today


In tip 0568 How do I convert a file name to lowercase, I used the replace syntax of the SET command to rename a file name to lower case.

In tip 7852, FileCase.exe freeware can rename a file name to lower case.

Using only standard commands, I have scripted LwrCase.bat and LwrCase_Folder.bat, to rename a file name to lower case, or rename all file names in a folder to lower case.

To rename a file name to lower case, use:

[call] LwrCase FullyQualifiedFileName

Where FullyQualifiedFileName is the fully qualified file name to be renamed.

To rename all the files names in a directory, use:

[call] LwrCase_Folder FullyQualifiedDirectoryName [/S]

where FullyQualifiedDirectoryName is the fully qualify folder path, and /S is an optional parameter that will also rename files names in all sub-folders.

NOTE: LwrCase.bat makes use the the /L switch of the DIR command, which returns lower case names.

LwrCase.bat contains:

@echo offif {%1}

{} @echo Syntax: LwrCase FullyQualifiedFileName&goto :EOFif not exist %1 @echo LwrCase - %1 NOT found.&goto :EOFsetlocalfor /f "Tokens=*" %%a in ('@echo %~a1') do ( set file=%%a)if /i "%file:~0,1%" EQU "d" @echo LwrCase - %1 is NOT a file.&endlocal&goto :EOFfor /f "Tokens=*" %%f in ('dir %1 /L /b /a /a-d') do ( Rename %1 "%%f")endlocal

LwrCase_Folder.bat contains:

@echo offif {%1}{} @echo Syntax: LwrCase_Folder FullyQualifiedDirectoryName&goto :EOFif not exist %1 @echo LwrCase_Folder - %1 NOT found.&goto :EOFsetlocalfor /f "Tokens=*" %%a in ('@echo %~a1') do ( set folder=%%a)if /i "%folder:~0,1%" NEQ "d" @echo LwrCase_Folder - %1 is NOT a folder.&endlocal&goto :EOFpushd %1set sw=/B /A /A-Dif /i {%2}=={/S} set sw=%sw% %2for /f "Tokens=*" %%f in ('dir %sw%') do ( call LwrCase "%%f")popdendlocal



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like