• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

Batch REN, removing a word from a file with 2 .dots.

Alright, so here's my deal.  I'm not the most profficent with DOS batch commands, but I'm trying to create a scheduled task to handle removing a word from all files in a specific folder daily.

The folder contains files named like this:

I want to remove the _white from all filenames, no matter where it is.

The examples I've found, described below, break when there are two dots in the statement, breaking the delims, I believe.

For what it's worth, the _white word should always be right before the jpg, so if there was a way to remove "_white.jpg" and tack on .jpg, that would work as a solution.


@echo off&for %%f in (*_white*) do call :ProcessFile %%f
goto :eof
echo %1
for /F "delims=_. tokens=1,3" %%c in ("%1") do ren "%1" "%%c.%%d"

Open in new window

1 Solution
QlemoBatchelor and DeveloperCommented:
@echo off
setlocal EnableDelayedExpansion
for %%F in (*_white*) do (
  set file=%%F
  ren !file! !file:_white.jpg=.jpg!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now