0

I've never written a script before so this could be a simple one but I couldn't find any previous answers for the matter. (probably because I don't really speak the language :D)

So I have in a folder 160 or so .ini files which all contain the variable "fill_dist = n".

I need to replace the n in all of these files and am not keen on doing it manually file by file.

This value (n) differentiates between .ini files so I can't find+replace the whole string. The replacement value would be the same for all .ini files though. (10000)

The row of this variable also differs depending on file. It seems to be written to the row after "cube_size" in every file though.

Any ideas?


Example .ini 1:

[Field]
cube_size = 400
fill_dist = 1600
diffuse_color = 220, 220, 180
ambient_color = 120, 120, 120
ambient_increase = 70, 40, 30
empty_cube_frequency = 0.6

Example .ini 2:

[Field]
cube_size = 400
fill_dist = 1500
diffuse_color = 220, 255, 255
ambient_color = 70, 70, 70
ambient_increase = 40, 40, 40
empty_cube_frequency = 0.5
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • If there are not too many variations, I would recommend using Notepad++ and simply performing a handful of mass replaces. – UnhandledExcepSean Feb 25 '15 at 23:27
  • I'll definitely try that out, thanks! Do you know the answer straight up if Notepad++ has a function to view(print) all values to said variable within all files in the folder? EDIT: Yeah it seems N++ does that sorta thing automagically! :D 153 hits and the variance seems to be like 10 different values by a quick look. – Paavo Virtanen Feb 25 '15 at 23:36
  • Grab `ini.bat` from the **Update** section of [this answer](http://stackoverflow.com/a/15413717/1683264). Then from a command line just do `for %I in (*.ini) do ini.bat /i fill_dist /v 10000 "%~I"`. No need to re-invent the wheel. :) Be advised that this will modify the `fill_dist` value if exist, or add it if not. If you don't want it added if it doesn't already exist, you'll need to use `for /f "delims=:" %I in ('findstr "fill_dist" *.ini')` instead. – rojo Feb 26 '15 at 00:15
  • Thanks for the helpful answers! Notepad++ and mass replace got the job done this in this case. :) – Paavo Virtanen Feb 26 '15 at 00:39

0 Answers0