Simple batch script

Home built / HOME BUILT
December 31, 2009 at 16:28:20
Specs: Windows XP x86 SP3 , 4 GB
I need a script to parse about 1500 flat .properties files. I need to find a given property and it replace part of the string. Some of the files already have this property updated, but I need to fix the older files. The files do contain several other lines.

The old files contain a property that looks like this:


I need to change it to look like this:


Basically just, parse all files in G:\Media\Movies\ with the extension .properties, and replace _userRating with UserRating and remove the trailing /10. Any decimals need to be removed as well. So 6.2 becomes just 6.



See More: Simple batch script

Report •

January 1, 2010 at 03:30:48
Hi Tony,

Long time no see.

@echo off > newfile & setLocal enableDELAYedeXpansion

pushd G:\Media\Movies

for /f "tokens=* delims= " %%a in ('dir/b *.properties') do (
del newfile
for /f "tokens=* delims= " %%i in (%%a) do (
set S=%%i
if !S:~0^,11! equ _userRating (
set S=UserRating!S:~11,2!
>> newfile echo.!S!
copy newfile %%a > nul
del newfile

Helping others achieve escape felicity


Report •

January 1, 2010 at 04:06:44
I'm sure the code works, but I have 1 concern with this:

When I'm replcaing (updating) the contents of a file, I only change the files that need changes. This has many advantages, one them is controlling your actions, since you can compare the result with your expectations. After a while, you won't see any changes being made. And if there are, something (or somebody) is still causing wrong syntax somewhere, so you can get rid of that.

How would that be done ? I know that DIFF and CMP are not easy on Windows batch, but that is not an excuse.

Report •

January 1, 2010 at 09:26:21
Thanks a lot M2go. I haven't been on these forums for quite
sometime now. Been too busy with...well life. Thanks a lot. I'll
try it as soon as I get home.


Report •

Related Solutions

Ask Question