Search code examples
dosfilenames

DOS renaming files troubleshooting


I am trying to batch rename several files that are named using the following scheme: picture.scn_xxx.png.

  • The placeholder xxx a numerical value ranging from 00000001 to (possibly) 99999999.
  • I would like to remove .scn to just have picturexxx.png.

I've tried the following in command:

ren picture.scn_*.png image*.png

However, this does not give me the desired result, I get image.scn_xxx.png instead. The .scn isn't removed( I was hoping to get imagexxx.png)


Solution

  • for /f "tokens=1* delims=_" %A in ('dir /b /a-d "picture.scn_*.png"') do ren "picture.scn_%B" "picture%B"
    

    If used in a batch file then %A and %B must change to %%A and %%B