Subscribe to Windows IT Pro
August 16, 2004 12:00 AM

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

Windows IT Pro
InstantDoc ID #81612
Rating: (0)


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 off
if {%1}

{} @echo Syntax: LwrCase FullyQualifiedFileName&goto :EOF if not exist %1 @echo LwrCase - %1 NOT found.&goto :EOF setlocal for /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 :EOF for /f "Tokens=*" %%f in ('dir %1 /L /b /a /a-d') do ( Rename %1 "%%f" ) endlocal

LwrCase_Folder.bat contains:
@echo off
if {%1}{} @echo Syntax: LwrCase_Folder FullyQualifiedDirectoryName&goto :EOF
if not exist %1 @echo LwrCase_Folder - %1 NOT found.&goto :EOF
setlocal
for /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 :EOF
pushd %1
set sw=/B /A /A-D
if /i {%2}=={/S} set sw=%sw% %2
for /f "Tokens=*" %%f in ('dir %sw%') do (
 call LwrCase "%%f"
)
popd
endlocal



Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.