如果实际应用场合没有那么多纯P的'天敌',变量名字典真是纯P代码得以如此轻快的一个好方法。
再给一个jscript+纯P混编的版本(存盘为.cmd或.bat文件),但愿能助纯P一臂之力...- @set @v=1 /*
- @echo off
- ::当前目录(不含子目录)下所有*.txt文件去重
- dir /b/a-d *.txt>"tmp.all"
- cscript /e:jscript "%~f0" "tmp.all"
- del /q "tmp.all"
- exit/b
- */
- var v = WSH.arguments;
- var fso = new ActiveXObject('scripting.filesystemobject');
- var fp = fso.opentextfile(v(0));
- var strline = fp.readall(); fp.close();
- var alllines = strline.split('\r\n');
- while (alllines[alllines.length-1] == '') alllines.length--;
- for (var n=0, nmax=alllines.length; n<nmax; ++n) {
- var txtF = alllines[n].replace(/\r\n/g, '');
- fp = fso.opentextfile(txtF);
- strline = fp.readall(); fp.close();
- var _strline = '\r\n', _alllines = strline.split('\r\n');
- while (_alllines[_alllines.length-1] == '') _alllines.length--;
- for (var k=0, kmax=_alllines.length; k<kmax; ++k) {
- if (_strline.indexOf('\r\n'+_alllines[k]+'\r\n') == -1)
- _strline += _alllines[k]+'\r\n';
- }
- if (_strline == '\r\n') continue;
- fp = fso.opentextfile(txtF+'.new', 2, true);
- fp.write(_strline.substr(2)); fp.close();
- }
- WSH.quit();
复制代码
|