Solved Need to increment a value

October 21, 2015 at 21:42:25
Specs: Windows 10 64 bit, Intel 3770
Hi there,
This is a working script that finds and replaces the text in a file in one single instance.
I need to be able to parse an entire directory of *.gdt and modify each file (like I've done below), but increment a number in the replaced field (as below)

set "replace=somesortofincrementingcounter"
every time it moves to the next file.

the beginning of the GDT text file (unmodified) is this:
"bo2-0" ( "material.gdf" )

Same file, modified, looks like this:
"somesortofincrementingcounter" ( "material.gdf" )
In place of "somesortofincrementingcounter", i'd like a number that gets incremented every time it moves to the next file in the directory. If it finds something like a "10" in the quotes, it would increment the next one to "11", the next to "12" and so on until it doesn't find any more files.
I will NOT be sending the modification to a new file as I have done below. (I did it so I didn't have to keep modifying it back)

Any help would be appreciated.
Thanks in advance.

--- code ---

@echo off

set "newfile=blackops2-modified.gdt"
set "search=bo2-0"
set "replace=somesortofincrementingcounter"
set "input_filename=blackops2.gdt"

(for /f "delims=" %%i in (%input_filename%) do (
set "line=%%i"

setlocal enabledelayedexpansion

set "line=!line:%search%=%replace%!"




message edited by RaGe

See More: Need to increment a value

Report •

October 22, 2015 at 01:57:03
✔ Best Answer
To perform mathematical operations on a value, use

set /a


Adding (What you'd wanna do in your script)

set /a value=%value%+1


set /a value=%value%*2


set /a value=%value%-3

Dividing (Doesn't work too well because floating point variables or something, but there are workarounds)

set /a value=%value%/2


set /a value=%value% %% 5

Marking answers that solve, or help helps you solve a problem as "Best Answer" also helps other people solve similiar ones in the future.

message edited by RainBawZ

Report •
Related Solutions

Ask Question