0

I have some files like:

f0110_01_online.png

f0122_01_01_online.png

f0122_0201_online.png

There is common text '_online' in every filename.

I just want to remove '_online' from every filenaeme with just a one line program in a .bat file because every time filenamses and number of files will change.

I am trying:

ren *_online.png *.png

but its not working.

Please suggest me proper way to do it in a batch file

1

You might be interested in the answer to How does the Windows RENAME command interpret wildcards?

Unfortunately, the REN command alone cannot give you your desired result. You could eliminate online using ren *_online.png *_.png, but elimination of the _ is impossible with the REN command alone.

The simplest solution using native commands is a small batch file:

@echo off
setlocal enableDelayedExpansion
for /f "eol=: delims=" %%F in ('dir /b *_online.png') do (
  set "file=%%F"
  ren "!file!" "!file:~0,-11!.png"
)

In the unlikely event that you have file names that contain the ! character, you would need:

@echo off
setlocal disableDelayedExpansion
for /f "eol=: delims=" %%F in ('dir /b *_online.png') do (
  set "file=%%F"
  setlocal enableDelayedExpansion
  ren "!file!" "!file:~0,-11!.png"
  endlocal
)
| improve this answer | |
  • Link is almost too much! Definitely read "How does the Windows RENAME (REN) command interpret wildcards? by dbenham. Note question example and consequent answer assumes constant text appended to the end. – BillR Nov 19 '13 at 19:11
0

I dont know how to using batch file. But i have a easy way to achieve your demand. You can using Total commander and using Multi Rename Tool, combine with regex option to mass rename file you want. I hope this tip can help you

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.