回复 13# huangfei3777 - /*&cls&echo off
- del "$合并结果.csv" 2>nul
- dir /a-d/b *.csv|cscript -nologo -e:jscript "%~f0">"$.tmp"
- ren "$.tmp" "$合并结果.csv"
- pause&exit
- */
-
- var fso = new ActiveXObject('Scripting.FileSystemObject'), a=[], b=[], n=0, m=1, max=0, s='';
- for(var i=0;i<5000;i++)s+=',';
- while(!WSH.StdIn.AtEndOfStream){
- var line = WSH.StdIn.ReadLine();
- var f = fso.OpenTextFile(line, 1);
- try{
- var txt = f.ReadAll().split(/[\r\n]+/);
- f.Close();if(txt.length>=max)max=txt.length;
- for(var i=0;i<txt.length;i++){
- if(!/"/.test(txt[i])){
- b[m]=txt[i].split(',').length;
- n+=b[m];break;
- }
- }
- for(var i=0;i<max;i++){
- if(a[i]){
- if(i<txt.length){
- a[i]+=','+txt[i];
- }else {a[i]+=s.substr(0, b[m]);}
- }else{
- if(m==1){
- a[i]=txt[i];
- }else a[i]=s.substr(0, n-b[m])+txt[i];
- }
- }
- m++;
- }catch(e){}
- }
- for(var b in a)WSH.echo(a[b]);
复制代码
|