GentlemanS
GentlemanS

Reputation: 121

Recursive Rename of Files and Folders in a Given Directory with BATCH

I'm trying to recursively rename all files and folders in a given directory to the uppercase version of whatever it is currently named. Lurking has gotten me this far:

@echo off
setlocal enableDelayedExpansion

pushd F:\

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

However, it doesn't seem to be working recursively. Any suggestions on how I can fix this?

Upvotes: 0

Views: 254

Answers (1)

Magoo
Magoo

Reputation: 79983

change

for %%f in (*) do (
   set "filename=%%~f"

to

for /r %%f in (*) do (
   set "filename=%%~nxf"

Which traverses the entire tree and assigns simply the name and extension of %%f to filename.

Note that

for /r "F:\" %%f in (*) do (

will start the search at the quoted directoryname.

Upvotes: 2

Related Questions