Computing.Net > Forums > Programming > setting values in patch file .ini

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

setting values in patch file .ini

Reply to Message Icon

Name: Erasmus1980
Date: December 1, 2008 at 00:58:46 Pacific
OS: XP
CPU/Ram:
Product: intel
Comment:

Hi,

I am using an .ini file that adds information to another file, but the problem is that i need to add the same values to about 1000 files. At this stage i add it to every file individually, because i have to change 4 of the values to have the same value as the name of the file i import it into. I am doing this manually, so you can understand how long this is taking me.

Is there a way to make the .ini file change these values to the mane of the file i import it into automatically?

As you can see i am a bit wet behind the ears with this and any help will be much appreciated.

The code is:

[add]
40000=4
40003=5066(This is the value that should take on the name of the file i import it into )A1
40008=-3.8932
40009=2.8182
40010=0.2343
40013=6
40014=0
40015=0
40023=5066(This is the value that should take on the name of the file i import it into )A2
40028=-1.5558
40029=0.1573
40030=-0.4006
40033=6
40034=0
40035=0
40043=5066(This is the value that should take on the name of the file i import it into )A3
40048=0.5337
40049=2.0390
40050=-0.3812
40053=6
40054=0
40055=0
40063=5066(This is the value that should take on the name of the file i import it into )A4
40068=-1.8115
40069=4.7006
40070=0.2500
40073=6
40074=0
40075=0



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: December 1, 2008 at 21:07:08 Pacific
Reply:

Erasmus,

This is what I understood from your problem statement. Let me know if I a right.
You have a ini file named XYZ.ini. Which appears like this:


[add]
40000=4
40003=Test1
40014=0
40015=0
40023=Test2
40028=-1.5558
40035=0
40043=Test3
40048=0.5337
40055=0
40063=Test4
40068=-1.8115
40074=0
40075=0

You have to replace
Test1 by XYZA1,
Test2 by XYZA2,
Test3 by XYZA3,
and Test4 by XYZA4.
In this example, it is test1, test2, test3 & test4.
Ideally you have to replace whatever is to the right of = sign against 40003, 40023, 40043 and 40063 by {filename}A1, {filenname}A2, ....
Is that right?

--
Holla.


0

Response Number 2
Name: Erasmus1980
Date: December 2, 2008 at 01:59:12 Pacific
Reply:

Thank you for responding.

I import the .ini file into a file called, for example, 6000.zfs. The .zfs file acts like a database and the information in the .ini file gets added to this database. The values in the .ini file that i am trying to change when i import the file into the .zfs file should have the same value as the name of the .zfs file i am trying to import it into. In other words I have to replace whatever is to the right of = sign against 40003, 40023, 40043 and 40063 by {filename}A1, {filenname}A2, ... Where filename is the same as the name of the .zfs file i import it into.


0

Response Number 3
Name: Holla
Date: December 2, 2008 at 09:42:35 Pacific
Reply:

Erasmus,
Try this: (please back up your .zfs files before trying)...
and let me know the progress..
remove @echo off if you have to debug.


@echo off
setlocal enableDelayedExpansion
for %%A in (*.zfs) do (
if exist %%A.tmp del %%A.tmp
set flnm=%%~nA
for /f "tokens=1,2* delims==" %%B in (%%A) do (
:echo bcd= %%B %%C %%D
set CCC=%%C
if [%%B]==[40003] (set CCC=!flnm!A1)
if [%%B]==[40023] (set CCC=!flnm!A2)
if [%%B]==[40043] (set CCC=!flnm!A3)
if [%%B]==[40063] (set CCC=!flnm!A4)
if [!CCC!]==[] (
echo %%B >> %%A.tmp
) else (
echo %%B=!CCC! >> %%A.tmp
)
)
del %%A
move %%A.tmp %%A
)

You will lose empty lines(if any) from .zfs file though.

--
Holla.


0

Response Number 4
Name: Erasmus1980
Date: December 2, 2008 at 22:57:43 Pacific
Reply:

When i run this script it deletes the .zfs files from it's folder. Any idea why this is happening?

It also says that the system can not find the file.



0

Response Number 5
Name: Holla
Date: December 3, 2008 at 03:00:44 Pacific
Reply:

Erasmus,
A dumb q, Do you have write permission on the disk?

The three commands that can make the file disappear is
1. if exist %%A.tmp del %%A.tmp
2. del %%A
3. move %%A.tmp %%A

prefix those statements with "echo" and insert a "pause" statement immediately after that.
That way you would be able to see what it is trying to do.
Hope you have understood the logic of the script.
What the script does is


For each *.zfs (
For each line read from the file (
parse the line: %B=token1, %C=token2&rest (delemeter is '=')
If the first token is of interest to us, do the replacement.
Output the new tokens to tmp file.
)
replace the original file by tmp file.
)

--
Holla.


0

Related Posts

See More



Response Number 6
Name: Erasmus1980
Date: December 3, 2008 at 05:03:45 Pacific
Reply:

Hi,

it does not delete the file anymore, it does look for the temp files and then delete them. Then it can not find the file it should edit and then it runs the delete file script. because it did not find any file to edit it also didn't create a temp file, so it does not replace the other file...

Hope that makes sence.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Bat file to del *.txt IF ... Install shared printer wi...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: setting values in patch file .ini

Adding values in text file via VBS www.computing.net/answers/programming/adding-values-in-text-file-via-vbs/15869.html

Changing a value in a xml file www.computing.net/answers/programming/changing-a-value-in-a-xml-file/19208.html

Find latest JRE in batch file www.computing.net/answers/programming/find-latest-jre-in-batch-file/15516.html