0

I'm trying to modify the code below to recursively rename all file types, not just a single type, within all subdirectories:

@echo off
Setlocal enabledelayedexpansion
Set "Pattern=rename"
Set "Replace=reuse"
For %%# in ("C:\Folder\*.jpg") Do (
Set "File=%%~nx#"
Ren "%%#" "!File:%Pattern%=%Replace%!"
)
Pause&Exit

Source: How to rename file by replacing substring using batch in Windows

Any help would be greatly appreciated!

Community
  • 1
  • 1
Newo
  • 9
  • 1

1 Answers1

0

Try this modification and if you found that the results are what you expected, just get rid from echo before the command Ren

@echo off
Setlocal enabledelayedexpansion
Set "Pattern=rename"
Set "Replace=reuse"
Set "MyFolder=%userprofile%\Desktop\test\*.*"
For %%# in ("%MyFolder%") Do (
    Set "File=%%~nx#"
    echo Ren "%%#" "!File:%Pattern%=%Replace%!"
)
Pause>nul & Exit
Hackoo
  • 18,337
  • 3
  • 40
  • 70