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


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



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish