Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename all files in folder to uppercase with batch

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")
like image 741
rikket Avatar asked Aug 08 '14 08:08

rikket


People also ask

Is there a way to batch rename files to uppercase?

This can be achieved with Microsoft PowerToys PowerRename feature. It adds a context menu to bulk-rename files, including the ability to capitalise and use Regular Expression.

Is there a way to rename multiple files at once with different names?

To rename multiple files from File Explorer, select all the files you wish to rename, then press the F2 key. The name of the last file will become highlighted. Type the new name you wish to give to every file, then press Enter.

How do I batch rename multiple files at once?

You can press and hold the Ctrl key and then click each file to rename. Or you can choose the first file, press and hold the Shift key, and then click the last file to select a group.


2 Answers

@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
like image 188
npocmaka Avatar answered Sep 28 '22 22:09

npocmaka


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.

like image 23
Samuel Champanhet Avatar answered Sep 28 '22 21:09

Samuel Champanhet