JS通过ActiveX读写ini配置文件
String.prototype.trim = function(){
return this.replace(/(^\s+)|(\s+$)/g, '');
};
IniConfig = function(iniFileName) {
this.iniFileName = iniFileName;
this._iniSecDictionary = new Array();
this.fso = new ActiveXObject("Scripting.FileSystemObject");
}
IniConfig.prototype._checkFile = function(){
if (!this.fso.FileExists(this.iniFileName)){
this.fso.CreateTextFile(this.iniFileName, true, true);
}
}
IniConfig.prototype.load = function(){
this._checkFile();
var currSecName = null;
var fs = this.fso.OpenTextFile(this.iniFileName, 1, false, -1);
while (!fs.AtEndOfStream) {
var strLine = fs.ReadLine().trim();
if (strLine.length > 0){
var firchCh = strLine.substr(0, 1);
if (firchCh != ';'){
if (firchCh == '['){
var secName = strLine.substr(1, strLine.length - 2);
currSecName = secName;
this._iniSecDictionary[secName] = new Array();
} else {
var idx = strLine.indexOf('=');
var strKey = strLine.substring(0, idx);
var strVal = strLine.substr(idx + 1);
if (currSecName == null){
throw ("Ini文件格式不正确!");
}
this._iniSecDictionary[currSecName][strKey] = strVal;
}
}
}
}
fs.Close();
fs = null;
}
IniConfig.prototype.save = function(){
this._checkFile();
var dic = this._iniSecDictionary;
var currSecName = null;
var fs = this.fso.OpenTextFile(this.iniFileName, 2, true, -1);
for (var sec in dic){
fs.WriteLine('[' + sec + ']');
for (var key in dic[sec]){
fs.WriteLine(key + '=' + dic[sec][key]);
}
}
fs.Close();
fs = null;
}
IniConfig.prototype.get = function(secName, keyName) {
var dic = this._iniSecDictionary;
try{
return dic[secName][keyName];
} catch (e) {
return '';
}
}
IniConfig.prototype.set = function(secName, keyName, val) {
var dic = this._iniSecDictionary;
try {
if (dic[secName] == null) {
dic[secName] = new Array();
}
dic[secName][keyName] = val;
} catch (e) {
alert(e.message);
}
}
try {
var iniFile = new IniConfig("E:\\a.ini");
iniFile.load();
alert(iniFile.get("Shutdown","0CmdLine"));
iniFile.set("Shutdown","0CmdLine","aaa");
iniFile.set("Shutdown","0CmdLine","abc");
iniFile.set("Shutdown", "1CmdLine", "bbb")
iniFile.save();
} catch(e) {
alert(e.message);
}
JS通过ActiveX读写ini配置文件的更多相关文章
- C# 读写 ini 配置文件
虽说 XML 文件越发流行,但精简的 ini 配置文件还是经常会用到,在此留个脚印. 当然,文中只是调用系统API,不会报错,如有必要,也可以直接以流形式读取 ini文件并解析. /// <su ...
- [转]VB 读写ini 配置文件
转自 百度知道 C# 读写 ini配置文件 点此链接 'API 声明Public Declare Function GetPrivateProfileString Lib "kernel32 ...
- 自己写的 读写 ini 配置文件类
/// <summary> /// 不调用系统API 读写 ini 配置文件 /// </summary> public class RW_ini { #region ==== ...
- 引用“kernel32”读写ini配置文件
引用"kernel32"读写ini配置文件 unity ini kernel32 配置文件 引用"kernel32"读写ini配置文件 OverView ke ...
- C# 文件的一些基本操作(转)//用C#读写ini配置文件
C# 文件的一些基本操作 2009-07-19 来自:博客园 字体大小:[大 中 小] 摘要:介绍C#对文件的一些基本操作,读写等. using System;using System.IO;us ...
- C#操作读写INI配置文件
一个完整的INI文件格式由节(section).键(key).值(value)组成.示例如:[section]key1=value1key2=value2; 备注:value的值不要太长,理论上最多不 ...
- c#读写ini配置文件示例
虽然c#里都是添加app.config 并且访问也很方便 ,有时候还是不习惯用他.那么我们来做个仿C++下的那种ini配置文件读写吧 其他人写的都是调用非托管kernel32.dll.我也用过 ...
- WritePrivateProfileString等读写.ini配置文件
配置文件中经常用到ini文件,在VC中其函数分别为: 写入.ini文件: BOOL WritePrivateProfileString( LPCTSTR lpAppName, // INI文件中的一个 ...
- C++读写ini配置文件GetPrivateProfileString()&WritePrivateProfileString()
转载: 1.https://blog.csdn.net/fengbingchun/article/details/6075716 2. 转自:http://hi.baidu.com/andywangc ...
随机推荐
- 什么是php面向对象及面向对象的三大特性
什么是面向对象? 面向对象编程,也就是我们常说的OOP,其实是面向对象的一部分.面向对象一共有3个部分:面向对象分析(OOA).面向对象设计(OOD).面向对象编程(OOP).我们现在将要学习的就是面 ...
- 转,sql 50道练习题
SQL语句50题 -- 一.创建教学系统的数据库,表,以及数据 --student(sno,sname,sage,ssex) 学生表--course(cno,cname,tno) 课程表--sc( ...
- 使用 ServerSocket 建立聊天服务器-2
1. 从serverListener中可以看出,每一个客户端创建新的请求之后,都会把它分配给一个独立的chatsocket ,但是每一个ChatSocket都是相互独立的,他们之间并不能沟通,所以要新 ...
- C++构造函数的default和delete
C++11中,当类中含有不能默认初始化的成员变量时,可以禁止默认构造函数的生成, myClass()=delete;//表示删除默认构造函数 myClass()=default;//表示默认存在构造函 ...
- 工作流学习之--TPFlow数据库分析
一.TPFlow项目数据库表: 1. 流程相关: a. leipi_flow工作流表: b. leipi_flow_process流程步骤表: c. leipi_run_process运行过程表:记录 ...
- 51 NOD 1244 莫比乌斯函数之和(杜教筛)
1244 莫比乌斯函数之和 基准时间限制:3 秒 空间限制:131072 KB 分值: 320 难度:7级算法题 收藏 关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens) ...
- 通过时间戳批量删除hbase的数据
如何通过时间戳批量删除hbase的数据 我们使用hive关联hbase插入数据时,有时会写错数据,此时hbase中的数据量已经很大很大了(上亿).此时,我们要修改错误的数据,只需要删除写错的那部分数据 ...
- 一个简单的python实现百度登录操作
conftest作为全局调用,用于登录之后的其他元素使用,且保持登录状态的操作 在开始前需要搭建好测试环境,环境包含python+webdriver+浏览器驱动(此处为firefox) 1.conft ...
- mybatis xml中是sql语句报错: Error creating document instance. Cause: org.xml.sax.SAXParseException: The
最近项目折腾了老半天,找了资料才知道是这么回事... 因为语句中有一个小于号“<”,在XML中,会被当成一个页面元素来解析,不会处理为mysql的SQL语句的组成部分,修改如下: 1.在xml的 ...
- 最简单的SpringAop 小案例
网盘下载地址: 链接:https://pan.baidu.com/s/1Z-em-1ouWyXeMP3JW0IbCg 提取码:0o4o 1.目录结构: 2.配置文件 applicationCo ...