Solved

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

Posted on 2009-04-07
1
433 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 69

Accepted Solution

by:
Qlemo earned 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
equivalent of dsquery in POWERSHELL (WIN7) 5 407
Windows Batch File - Count Down 4 107
Batch file or script with password 22 91
Windows updates batch files 7 105
Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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