Sign in to follow this  
Followers 0
dcjohnston

Ini Read and write challenge

9 posts in this topic

I am a right brained guy trying to do something that is way over my head.

I have to edit 3 .ini files. they are called plat1.ini, plat2.ini and plat3.ini

I created a "changes.ini" file that is the central data file that the compiled exe will go to for information. It looks like this:

;-------------------------platserve.ini files go here --------------------------

[platnames]

PLATSERV = plat1.ini

PLATSERV = plat2.ini

PLATSERV = plat3.ini

;--------------------------plat*.ini changes go here--------------------------

[Defaults]

DPPhoneNbr=55555555555555

[Training]

DATABASE=YYYYYYYYYYYYYYY

[ADO]

DATABASE=XXXXXXXXXXXXXXXXXXXXX

;-----------------------------------------------------------------------------------

I need to take this data under plat*.ini using the iniread function and iniwrite it to each of the 3 plat#.ini files. The files needing to be edited reside on a mapped f: drive.

The challenge is to somehow loop reading this out of the "changes.ini" file and writing it to each of the 3 plat#.ini files.

Any help is GREATLY appreciated.

Dave

Share this post


Link to post
Share on other sites



To get this straight:

- You have a main script.

- A main INI file that has the name: changes.ini

Every client has a script that updates the changes.ini when necessary.

- When someone updates the changes.ini, all the other INI files will be updated by the main script.

Will the main script run frequently?

By one person or multiple users?

Share this post


Link to post
Share on other sites

A couple things here. First of all you cannot have mulitple values by the same name within the same section. This will ONLY ever return the first value in the file. Another thing, do you have control over the way the changes INI is formatted or is there any standard parameters you have to check for? You dont give enough information about the source of this information to be able to generate a good complete script.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

To get this straight:

- You have a main script.

Correct. A Compiled autoit.exe file called platupgrade.exe. This exe goes to the c:\changes.ini file for upgrade information. This changes.ini file contains the information that will need to be placed in the plat1.ini file that exists on the mapped f: drive. This is from the changes.ini file.

;--------------------------plat*.ini changes go here--------------------------

[Defaults]

DPPhoneNbr=55555555555555

[Training]

DATABASE=YYYYYYYYYYYYYYY

DATABASE=ZZZZZZZZZZZZZZZ

[ADO]

DATABASE=XXXXXXXXXXXXXXXXXXXXX

- When someone updates the changes.ini, all the other INI files will be updated by the main script.

Correct. I make changes to the changes.ini file and the .exe goes and says:

OK, I need to update the f:\pltrsm\platform.ini [Defaults] section with DPPhoneNbr=55555555555555

Then go to the [Training] section and add

DATABASE=YYYYYYYYYYYYYYY

DATABASE=ZZZZZZZZZZZZZZZ

Then under the [ADO] section add this line

DATABASE=XXXXXXXXXXXXXXXXXXXXX

Will the main script run frequently? Just once. It just needs to be able to read the data in the changes .ini file in a loop

By one person or multiple users? One person

Thanks

Dave

Share this post


Link to post
Share on other sites

Thanks Matt, good information.

The changes .ini file would contain this instead. I put the original information in as an example. This would be a better example.

[Defaults]

DPPhoneNbr=55555555555555

[Training]

Users=YYYYYYYYYYYYYYY

[ADO]

DATABASE=XXXXXXXXXXXXXXXXXXXXX

A couple things here. First of all you cannot have mulitple values by the same name within the same section. This will ONLY ever return the first value in the file. Another thing, do you have control over the way the changes INI is formatted or is there any standard parameters you have to check for? You dont give enough information about the source of this information to be able to generate a good complete script.

*** Matt @ MPCS

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

[qoute]

;-------------------------platserve.ini files go here --------------------------

[platnames]

PLATSERV = plat1.ini

PLATSERV = plat2.ini

PLATSERV = plat3.ini

Share this post


Link to post
Share on other sites

Yes they will have a fixed name. So your change is good.

The .exe would need to start at the top of the [platnames] section and say:

I need to see if there is a plat1.ini file in the f:\pltrsm directory.

If there is then I need to make changes to it.

I will get that information from the changes.ini file

[Defaults]

DPPhoneNbr=55555555555555

[Training]

Users=YYYYYYYYYYYYYYY

[ADO]

DATABASE=XXXXXXXXXXXXXXXXXXXXX

else check to see if there is a plat2.ini and so on.

THanks

Dave

[qoute]

;-------------------------platserve.ini files go here --------------------------

[platnames]

PLATSERV = plat1.ini

PLATSERV = plat2.ini

PLATSERV = plat3.ini

Are these files always going to be the same? If not can I make a suggestion? Try this:

[platnames]
PLATSERV1=plat1.ini
PLATSERV2=plat2.ini
PLATSERV3=plat3.ini
PLATSERV4=platN.ini

*** Matt @ MPCS

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well I am completly spent on this... I will share the source I have typed but it won't do what you want yet. It still has quite the distance before it is complete. Hopefully it gives someone an idea somewhere.

Dim $i, $j
Dim $tmpINIValue, $tmpINIValue2
Dim $PLATSERVFILE
Dim $arrMatchKeys

Dim $CONFIGFILE = "config.ini"

$PLATSERVFILE = IniRead( $CONFIGFILE, "Main", "PlatServFile", "platserv.ini" )
$tmpINIValue = IniRead( $CONFIGFILE, "Main", "MatchKeys", "" )

$arrMatchKeys = StringSplit( $tmpINIValue, "|" )

$i = 0

While 1
   $i = $i + 1
   
   $tmpINIValue = IniRead( $PLATSERVFILE, "[platnames]", "PLAT" & $i, "" ) 
   
   If $tmpINIValue <> "" Then
      
      For $j = 1 to $arrMatchKeys[0]
      
      Next  
      
   Else
      
      ExitLoop
      
   EndIf
   
Wend

Sorry I couldn't finish it.

*** Matt @ MPCS

Edited by Matt @ MPCS

Share this post


Link to post
Share on other sites

Matt, Excellent,

I see what you are going. Man I owe you one.

Thanks for your time. I will give you credit in my code.

Thanks again for your assistance...

Dave

Well I am completly spent on this...  I will share the source I have typed but it won't do what you want yet. It still has quite the distance before it is complete. Hopefully it gives someone an idea somewhere.

Dim $i, $j
Dim $tmpINIValue, $tmpINIValue2
Dim $PLATSERVFILE
Dim $arrMatchKeys

Dim $CONFIGFILE = "config.ini"

$PLATSERVFILE = IniRead( $CONFIGFILE, "Main", "PlatServFile", "platserv.ini" )
$tmpINIValue = IniRead( $CONFIGFILE, "Main", "MatchKeys", "" )

$arrMatchKeys = StringSplit( $tmpINIValue, "|" )

$i = 0

While 1
   $i = $i + 1
   
   $tmpINIValue = IniRead( $PLATSERVFILE, "[platnames]", "PLAT" & $i, "" ) 
   
   If $tmpINIValue <> "" Then
      
      For $j = 1 to $arrMatchKeys[0]
      
      Next  
      
   Else
      
      ExitLoop
      
   EndIf
   
Wend

Sorry I couldn't finish it.

*** Matt @ MPCS

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0