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!

2
  • *.jpg --> *.*, and for --> for /R; Commented Aug 27, 2016 at 14:35
  • Hmmm. Not working. Did I add correctly? For /R in ("C:\Users\HTPC\Desktop\test*.*") Do ( Commented Aug 27, 2016 at 16:15

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.