- /*&cls
- @echo off
- set "file=文本.txt"
- set "keywords=关键字"
- set "addstr=添加的内容"
- set "tmpfile=$tmp.txt"
- cscript -nologo -e:jscript "%~f0" "%file%" "%tmpfile%" "%keywords:\=\\%" "%addstr%"
- rem move "%tmpfile%" "%file%"
- pause&exit
- */
-
- var fso=new ActiveXObject('Scripting.FileSystemObject');
- var text=fso.OpenTextFile(WSH.Arguments(0), 1).ReadAll();
- var keywords=WSH.Arguments(2).replace(/[*.?+$^[\](){}|/]/g, '\\$&')
- var reg=new RegExp(keywords+'[^\\r\\n]*')
- var text=text.replace(reg, '$&'+WSH.Arguments(3));
- fso.CreateTextFile(WSH.Arguments(1), 2).Write(text);
复制代码
|