本帖最后由 WHY 于 2015-12-22 16:46 编辑
- @set @n=0;/* & echo off
- set "fd=D:\数据\新文本\"
- md "%fd%" 2>nul
- pushd D:\数据\
- dir /b *.txt | cscript -nologo -e:jscript "%~0" "%fd%"
- pause & exit
- */
-
- var fd = WScript.Arguments(0);
- var fso = new ActiveXObject('Scripting.FileSystemObject');
-
- while (!WScript.StdIn.AtEndOfStream){
- var file = WScript.StdIn.ReadLine();
- var arrRow = readTextFile(file).split('\n'); //分割行
- var x = [], y = [], max = 0;
-
- //文本数据存放在数组x
- for(var i=0; i<arrRow.length; i++){
- x[i] = arrRow[i].match(/\S/g); //分割列
- if (x[i].length > max) max = x[i].length //最大列数
- }
-
- //每一列数据拼接成字符串、排序、存放在数组y
- for(var i=0; i<max; i++){
- var s = '';
- for(var j=0; j<arrRow.length; j++) s += x[j][i];
- y[i] = getNum(s);
- }
-
- //重组数据、输出
- var s = '';
- for(i=0; i<=9; i++){
- var s1 = '';
- for(var j=0; j<max; j++) s1 += ' ' + y[j][i];
- s += s1.replace(/ \d+=\d+=/g, '') + '\r\n';
- }
- fso.OpenTextFile(fd + file, 2, true).Write(s);
- }
-
- function readTextFile(strFile){
- var objFile = fso.OpenTextFile(strFile, 1);
- var s = objFile.ReadAll() + '\n';
- s = s.replace(/(\s*\n)+/g, '\n').replace(/^\n|\n$/g, '');
- objFile.Close(); objFile = null;
- return s
- }
-
- function getNum(s) {
- var ar = [];
- for (var i=0; i<=9; i++) {
- var s1 = 100000000000000 - s.split(i).length;
- var s2 = 100000000000001 + s.indexOf(i);
- ar.push(s1 + '=' + s2 + '=' + i);
- }
- return ar.sort();
- }
复制代码
|