0

I have lists of files I would like to batch rename.

Source files names are "SlideXX.BMP" (XX being number from 1 to whatever).

I would like to rename them all to "bbrdXX.BMP"

When I perform ren Slide* bbrd* the ren performs but unlike expected everything becomes "bbrdeXX.BMP".

Why does this occur?

3 Answers3

0

Slide is 5 letters long. BBRD is 4 letters long. If you can use bbrd_ then the e will get replaced also. If you are willing to do two steps :

  • ren "Slide*" "/."
  • ren lide* bbcd*

The first ren strips the S or reduces the length by one. The second ren then does the conversion to bbrd without error since lide has 4 letters also

bvaughn
  • 751
0

I'd go with PowerShell on this, in cmd it could be a little more complicated to achieve what you want.

$x = gci C:\yourpath | % { gi $_.FullName | rni -newname ($_ -replace "Slide","bbrd") }

In Detail:

  • First it searches for all files inside the directory with Get-ChildItem alias gci
  • Then it will loop over each file with foreach-object alias %
  • Then it calls the Item by it's fullname property with get-item alias gi
  • The Item then gets passed into the pipeline and renamed by rename-item alias rni
  • Inside the rni part, it replaces Slide with bbrd for the current object and will be saved with the new name.

to run this recursively if you have subfolders which also have files inside which need to be renamed, just add -r to your gci call and also add a filter to only target the files you want:

$x = gci C:\yourpath -r -filter *.bmp | % { [...] }

SimonS
  • 9,869
0

I don't think in batch there is complex scripting required. It is as simple as

@echo off & setlocal EnableExtensions EnableDelayedExpansion
for %%A in (Slide*.bmp) do Set A=%%~nxA&Ren "%%A" "!A:Slide=bbrd!"

If DelayedExpansion is Enabled by default it is also a console one liner:

for %A in (Slide*.bmp) do Set A=%~nxA&Ren "%A" "!A:Slide=bbrd!"
LotPings
  • 7,391