Using .INI files with ColdFusion
Here I will show how you can interact with .ini files. You might be wondering why do I want to interact with .ini files, when I can store the info into a dbase. Well if you have software that runs off an INI-file you can easily interact with it. Also if you have not made a connection to the Dbase you can store some info into an INI file.
First thing is the look of an INI file:
[settings]
user=john
password=12345
LocalPath=c:\john
To Read any of the values we use the following ColdFusion code:
<cfoutput>
Username : #GetProfileString(“C:\settings.ini”, “settings”, “user”)#<BR>
Password : #GetProfileString(“C:\settings.ini”, “settings”, “password”)#<BR>
FTP Path : #GetProfileString(“C:\settings.ini”, “settings”, “path”)#<BR>
</cfoutput>
This will get the info out of the INI-file and display it. You can also set it into a variable to use it later or in a different way.
<cfset MyName = GetProfileString(“C:\settings.ini”, “settings”, “user”) >
To Write to an INI file we use the following code:
<cfset temp = SetProfileString(“C:\settings.ini”, “settings”, “user”, “Dave”)>
That’s all there is to it. Once you start playing with it, you will find different uses for it.