- //&cls&dir /a-d/b *.txt|cscript -nologo -e:jscript "%~f0"&pause&exit
- var fso = new ActiveXObject('Scripting.Filesystemobject');
- var txtfiles = WSH.StdIn.ReadAll().split(/\r\n/);
- for(var i = 0; i<txtfiles.length; i++){
- var filename = fso.GetFile(txtfiles[i]).Name.replace(/\.[^\.]+$/, '');
- var f = fso.OpenTextFile(txtfiles[i], 1);
- var txt = f.ReadAll().replace(/(^|\r?\n)(?!(\r?\n|$))/g, '$&'+filename+',');
- f.Close();
- var f = fso.OpenTextFile(txtfiles[i], 2);
- f.Write(txt);
- f.Close();
- }
- WSH.echo('Done');
复制代码
|