My Recent Tweets

Follow @rkuiper72
Archives

Using .INI files with ColdFusion

Here I will show how you can inter­act with .ini files. You might be won­der­ing why do I want to inter­act with .ini files, when I can store the info into a dbase. Well if you have soft­ware that runs off an INI-file you can eas­ily inter­act with it. Also if you have not made a con­nec­tion to the Dbase you can store some info into an INI file.

First thing is the look of an INI file:

CF Code

[set­tings]
user=john
password=12345
LocalPath=c:\john

To Read any of the val­ues we use the fol­low­ing Cold­Fu­sion code:

CF Code

<cfout­put>
     User­name : #GetProfileString(“C:\settings.ini”, “set­tings”, “user”)#<BR>
     Pass­word : #GetProfileString(“C:\settings.ini”, “set­tings”, “pass­word”)#<BR>
     FTP Path : #GetProfileString(“C:\settings.ini”, “set­tings”, “path”)#<BR>

</cfoutput>

This will get the info out of the INI-file and dis­play it. You can also set it into a vari­able to use it later or in a dif­fer­ent way.

CF Code

<cfset MyName = Get­Pro­fileString(“C:\settings.ini”, “set­tings”, “user”) >

To Write to an INI file we use the fol­low­ing code:

CF Code

<cfset temp = Set­Pro­fileString(“C:\settings.ini”, “set­tings”, “user”, “Dave”)>

That’s all there is to it. Once you start play­ing with it, you will find dif­fer­ent uses for it.

Leave a Reply

You must be logged in to post a comment.