[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-07
1
Medium Priority
?
452 Views
Last Modified: 2012-06-21
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:
ABC0.75gy_white.jpg
DEF1.23AB_white.jpg

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.

Thanks!

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

Open in new window

0
Comment
Question by:Rookerin
1 Comment
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 24091914
@echo off
setlocal EnableDelayedExpansion
for %%F in (*_white*) do (
  set file=%%F
  ren !file! !file:_white.jpg=.jpg!
)

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question