- @set @n=0/*& echo off
- set "folder=d:\总文件夹"
- copy /y xxx.gs xxx.gs.bak
- cscript.exe -e:jscript "%~f0" "%folder%" || (pause&exit/b)
- echo grads -blc "%folder%\xxx.gs"
- rem do something you like.
-
- exit/b
- */
-
- folder = WScript.Arguments(0);
- file = folder + "\\xxx.gs";
- strQuery = "select name from CIM_DataFile where "
- + " drive='" + folder.substr(0,2) + "' and "
- + " path like '" + folder.substr(2).replace(/\\/g,'\\\\') + "\\\\%'"
- + " and extension='ctl'";
- wmi = new ActiveXObject("WbemScripting.SWbemLocator").ConnectServer();
- colFiles = wmi.ExecQuery(strQuery, "WQL", 48);
- e = new Enumerator(colFiles);
- arrFiles = [];
- for (; !e.atEnd(); e.moveNext()) arrFiles.push(e.item().name);
- txt = readtext(file);
- i = 0;
- txt = txt.replace(/^'open ([^']+)|^while\(i<=(\d+)\)/gm,
- function(s0,s1,s2){
- if (s1) return s0.replace(s1, arrFiles[i]);
- else return s0.replace(s2,
- readtext(arrFiles[i++]).match(/^tdef (\d+) linear/m)[1]);
- });
- writetext(file, txt);
-
- function readtext(file, charset)
- {
- var text;
- var aso = new ActiveXObject('ADODB.Stream');
- aso.Mode = 3;
- aso.Type = 2;
- if (charset) aso.Charset = charset;
- else aso.Charset = 'gbk';
- aso.Open();
- aso.LoadFromFile(file);
- text = aso.ReadText(-1);
- aso.Close();
- aso = null;
- return text;
- }
-
- function writetext(file, text, charset)
- {
- var aso = new ActiveXObject('ADODB.Stream');
- aso.Mode = 3;
- aso.Type = 2;
- if (charset) aso.Charset = charset;
- else aso.Charset = 'gbk';
- aso.Open();
- aso.WriteText(text);
- aso.SaveToFile(file, 2);
- aso.Close();
- aso = null;
- }
复制代码 继续将JavaScript发扬光大。 |