Reputation: 2407
Is there a way to rename all files in a specific folder to uppercase with batch file?
I found this code. But it renames files to lowercase. How to modify it to rename to uppercase instead?
for /f "Tokens=*" %f in ('dir /l/b/a-d') do (rename "%f" "%f")
Upvotes: 9
Views: 23080
Reputation: 43
This will convert all filenames in a directory to uppercase without affecting the extension.
rename 's/^([^.]*)\.(.*)$/\U$1\E.$2/' *
Upvotes: 1
Reputation: 63
This will put the extension to upper case as well.... Which was a problem for me... So this how I "kept" extension as lower case...
@echo off
setlocal enableDelayedExpansion
pushd "\...\PATH_TO_FOLDER\"
for %%f in (*) do (
set "filename=%%~f"
for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
set "filename=!filename:%%A=%%A!"
)
ren "%%f" "!filename!" >nul 2>&1
)
for /r "\...\PATH_TO_FOLDER\" %%G in (*.PDF) do ren "%%~G" *.pdf
endlocal
replace \...\PATH_TO_FOLDER\ with your path and .PDF/.pdf with your file extention as needed.
Upvotes: 2
Reputation: 57252
@echo off
setlocal enableDelayedExpansion
pushd c:\some_dir
for %%f in (*) do (
set "filename=%%~f"
for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
set "filename=!filename:%%A=%%A!"
)
ren "%%f" "!filename!" >nul 2>&1
)
endlocal
Upvotes: 14