- /*&cls
- @echo off
- ::指定在第一行之后插入
- set n=1
- dir /a-d /b *.txt|cscript -nologo -e:jscript "%~f0" %n%
- pause&exit
- */
- var fso = new ActiveXObject('Scripting.FileSystemObject');
- while(!WScript.StdIn.AtEndOfStream){
- var file = WScript.StdIn.ReadLine();
- var i = 0, s = '', f = fso.OpenTextFile(file, 1);
- while(!f.AtEndOfStream){
- if(i == WScript.Arguments(0))s += fso.GetFile(file).Name.replace(/\.[^\.]+$/, '') + '\r\n';
- var str = f.ReadLine();
- s += str + '\r\n';
- i++;
- }
- f.Close();
- var f = fso.OpenTextFile(file, 2);
- f.Write(s);
- f.Close();
- }
复制代码
|