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 ...
随机推荐
- Time 时间格式处理方法
一般时间调用都会精确到年 月 日 时 分 秒 怎么调用时去掉时 分 秒呢 用以下格式来处理 //时间格式处理 var time = new Date(data.FTime); var ...
- MySQL 优化--持续整理
一.innodb体系结构优化: 1.IO优化 IO能力不足时 innodb_io_capacity 应该降低 innodb_max_dirty_pages_pct 应该降低 innodb_max_di ...
- link cut tree 洞穴勘测
/*[bzoj2049][Sdoi2008]Cave 洞穴勘测 2014年7月30日1,06923Description 辉辉热衷于洞穴勘测.某天,他按照地图来到了一片被标记为JSZX的洞穴群地区 . ...
- chrome的内存限制
推荐阅读:https://www.cnblogs.com/chengxs/p/10919311.html chrome内存限制 存在限制 Chrome限制了所能使用的内存极限(64位为1.4GB,32 ...
- mvn ssm 异常 org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'multipartResolver'
解决方案: 添加 commons-fileupload-1.2.jar <!-- https://mvnrepository.com/artifact/commons-fileupload/co ...
- vue-cli构建路径加载资源出错问题
这份文档是对应 @vue/cli 3.x 版本的,官方文档https://cli.vuejs.org/zh/guide/ 项目打包执行npm run build的时候,打开dist目录的index.h ...
- JDBC工具类:JDBCUtils
1. 目的 每次使用JDBC的时候都要书写冗长的代码段,不符合复用的理念,于是要单独写一个类,将通用的JDBC操作写到一个类中,便于重复使用和精简代码. 2. 步骤 (1)注册驱动并获取连接 为了最大 ...
- createElement与createDocumentFragment的一些小区别
在DOM操作里,createElement是创建一个新的节点,createDocumentFragment是创建一个文档片段. 网上可以搜到的大部分都是说使用createDocumentFragmen ...
- go中json的tag使用
指定json中的key名字: 指定数据类型, string number, boolean 忽略空值(值不为空, 不忽略) 忽略字段 "-" (无论有没有值, 都忽略) type ...
- Windows安装Centos7双系统后Windows启动项消失
原文: https://www.cnblogs.com/xinglichao/p/9999049.html https://blog.csdn.net/yingzinanfei/article/det ...