本帖最后由 apang 于 2015-3-2 02:02 编辑
保存为test.bat,与a.txt放在同一目录- @set @n=0;// & cscript -nologo -e:jscript "%~0"<a.txt & pause & exit/b
-
- Path = "D:\\Test\\"
- fso = new ActiveXObject("Scripting.FileSystemObject");
- while (!WScript.StdIn.AtEndOfStream) {
- f = WScript.StdIn.ReadLine().replace(/^\s+|\s+$/g, "");
- f = Path + f;
- if (fso.FileExists(f)) {
- objFile = fso.OpenTextFile(f, 1);
- txt = objFile.ReadAll();
- objFile.Close();
- fso.OpenTextFile(f, 2).Write(changeNum(txt))
- }
- }
-
- function changeNum(s) {
- s += "\r\n";
- //ToolSpeed 的值乘以0.2
- re1 = /^( *\[Generating][\s\S]+?^ *ToolSpeed *=)(.*)\r\n/im;
- //Diameter 的值修改成80
- re2 = /^( *\[EdgeData][\s\S]+?^ *Diameter *=)(.*)\r\n/im;
- //Type=circle 修改为 Type=rand
- re3 = /^ *Type *= *circle *\r\n/im;
- //[EdgeData] 下面增加一行 PA=5.0
- re4 = /^ *\[EdgeData] *\r\n/im;
- //Wavi开头的行后面加上 -Q
- re5 = /^( *Wavi.*?)(\-Q)? *\r\n/img;
- //删除以Thickness开头的行
- re6 = /^ *Thickness.*\n/img;
- s = s.replace(re1,
- //加减除修改下面*为+-/
- function(s0,s1,s2){s2-=0; return s1 + (s2 * 0.2) + "\r\n"}
- );
- s = s.replace(re2, "$1" + "80" + "\r\n");
- s = s.replace(re3, "Type=rand" + "\r\n");
- s = s.replace(re4, "$&" + "PA=5.0" + "\r\n");
- s = s.replace(re5, "$1" + "-Q" + "\r\n");
- s = s.replace(re6, "");
- return s.replace(/\r\n$/, "")
- }
复制代码
|