2007年5月24日星期四

INI 文件相关内容

INI文件是微软为程序初始化设计的文件格式。这样的文件如系统盘下的Boot.ini, System.ini等。
最简单的就是如下
[Section]
Key=Value
; a comment line

INI文件并没有十分严格的相关规范,基本的内容可以参考:

wikipedia维基百科:http://en.wikipedia.org/wiki/INI_file


微软在Windows下有一个专门的库来读取操作ini文件


INI文件并非一定要在Windows下才能应用,因为它比较简单,所以在Linux系统下也有相关的应用,也有人编写了跨平台的操作ini文件的库(类)。现在,以XML作为初始化文件格式的程序也多了起来,而微软Windows平台下也有相当一部分的程序需要对注册表进行操作,将初始化信息写入注册表,然而这样就给程序的Portability拖了后腿。
下面对一些相关内容做简单的介绍。

CINI
http://www.codeproject.com/cpp/CIni.asp
这应该是应用最广的一个简单的ini操作类,上述的地址上有非常详细的函数介绍和源码(包括demo)的下载。

Introduction

While it is recommended that programmers should use system registry to store application initialization data, I found myself still using INI files often. I'm not going to discuss or compare the pro's and con's of registry and INI file in detail, but one main reason I use INI files is that, I believe an application should "infect" the system as little as possible, if it could be done by using an INI file, I will not use the registry.



SimpleIni
http://code.jellycan.com/simpleini/
下面是CodeProject网站上的介绍文章。
http://www.codeproject.com/useritems/SimpleIni.asp

一个简单的跨平台的用于读写INI格式配置文件的API
A cross-platform library that provides a simple API to read and write INI-style configuration files. It supports data files in ASCII, MBCS and Unicode. It is designed explicitly to be portable to any platform and has been tested on Windows and Linux. Released as open-source and free using the MIT licence.
How to read/write INI files in VBScript
http://www.motobit.com/tips/detpg_asp-vbs-read-write-ini-files/
C# - Read/Write XML files, Config files, INI files, or the Registry
http://www.codeproject.com/csharp/ReadWriteXmlIni.asp

当然,Google 一下你能找到更多:http://www.google.com/search?q=ini+read+write

没有评论: