保存为.js文件 | var fso = WScript.CreateObject('Scripting.FileSystemObject'), | | srcdir = 'E:/数据1', | | dstdir = 'E:/数据2'; | | | | for (colFiles = new Enumerator(fso.GetFolder(srcdir).Files); !colFiles.atEnd(); colFiles.moveNext()) { | | var ofile = colFiles.item(); | | try { | | var tsread = ofile.OpenAsTextStream(1, -2); | | var tswrite = fso.OpenTextFile(fso.BuildPath(dstdir, ofile.Name),2,true,-2); | | var arrLines = [], | | maxCols = 0; | | while (!tsread.atEndOfStream) { | | var arrSplit = tsread.readline().split('\t'); | | arrLines.push(arrSplit); | | maxCols = Math.max(maxCols, arrSplit.length); | | } | | var arrColumns = Array(maxCols); | | for (var i = maxCols - 1; i >= 0; i--) { | | arrColumns[i] = []; | | } | | for (i = 0; i < arrLines.length; i++) { | | for (var j = arrLines[i].length - 1; j >= 0; j--) { | | if (arrLines[i][j] !== '') { | | arrColumns[j].push(arrLines[i][j]); | | } | | } | | } | | | | var arrOut = ['']; | | for (i = arrColumns.length - 1; i >= 0; i--) { | | var arrOut_ = []; | | for (j = 0; j < arrColumns[i].length; j++) { | | for (var k = 0; k < arrOut.length; k++) { | | arrOut_.push(arrColumns[i][j] + arrOut[k]); | | } | | } | | arrOut = arrOut_; | | } | | | | tswrite.writeline(arrOut.join('\r\n')); | | } catch (e) { | | WScript.Echo(e.message); | | continue | | } finally { | | if(tsread){ | | tsread.close(); | | } | | if(tswrite){ | | tswrite.close(); | | } | | } | | }COPY |
|