0

I have some files in my folder like:

asd55.png
qwe55.png
zxc55.png

I want to remove the 55 and get the result:

asd.png
qwe.png
zxc.png

I tried with:

ren *55.png *.png

but doesnt work.

NOTE:

I have different name sizes like:

asd55.png
qwerty55.png
tato469
  • 155
  • 1
  • 7
  • 1
    ren ???55.png ??? See http://superuser.com/q/475874/109090 for an explanation – dbenham Sep 01 '14 at 11:24
  • 1
    @dbenham The command should be `ren ???55.png ???.png` The only caveat is that it only works if the file name length is always 5 (3+2). For a more generic solution, a batch script is the only way to go, I guess. – and31415 Sep 01 '14 at 11:29
  • well I have some different file name sizes. like wioqetr55.png and jsad55.png – tato469 Sep 01 '14 at 11:29
  • possible duplicate of [Batch Renaming Automation \*\_2.\* TO \*.\*](http://superuser.com/questions/720502/batch-renaming-automation-2-to) – and31415 Sep 01 '14 at 11:31
  • the soultion gived by @and31415 worked for me :) – tato469 Sep 01 '14 at 11:35
  • @and31415 - Yes, that was my intent. Just a momentary brain fart when I originally typed. – dbenham Sep 01 '14 at 11:37

1 Answers1

1
ren ???55.png ???.png

See How does the Windows RENAME command interpret wildcards? for an explanation

If the number of characters before 55 varies, then you will probably want to use a batch script. (Could be done with a fairly complicated one liner on the command line, but not worth it)

@echo off
setlocal enableDelayedExpansion
for /f "delims=" %%F in ('dir /a-d ?*55.png') do (
  set "name=%%~nF"
  ren "%%F" "!name:~0,-2!%%~xF"
)

If any file name might contain !, then delayed expansion must be toggled on and off within the loop.

@echo off
setlocal disableDelayedExpansion
for /f "delims=" %%F in ('dir /a-d ?*55.png') do (
  set "name=%%~nF"
  set "ext=%%~xF"
  setlocal enableDelayedExpansion
  ren "!name!!ext!" "!name:~0,-2!!ext!"
  endlocal
)
dbenham
  • 11,194
  • 6
  • 30
  • 47