Computing Staff
  • 0

Batch File Rename (Reorder Filename Parts)

  • 0

Hi. I have a folder of .pdf files I’d like to rename using a batch file. Each filename consists of three words separated by an underscore:

first_second_third.pdf

Would like to rename with this result:

third_second_first.pdf

Am still pretty new at batch file programming and appreciate the help!

Share

2 Answers

  1. @echo off & setlocal
    for /f “tokens=1-3 delims=_” %%a in (‘dir /b *.pdf’) do echo ren “%%_%%b_%%c.pdf” “%%c_%%b_%%a.pdf”
    ::— end
    i left the safety “on” (echo). If satisfied, just remove the “echo” from the command-string.

    • 0
  2. Assuming none of the filenames contains a dot (other than the extension), the dot would be the easiest way:
    for /f “tokens=1-3 delims=_.” %%a in (‘dir /b *.pdf’) do echo ren “%%a_%%b_%%c.pdf” “%%c_%%b_%%a.pdf”

    • 0