0

I have a strange issue with a batch file that combines multiple CSV files into one. This is the file I am using.

It will only take one of the CSV files of multiples in the directory and copies it's contents to the new.csv file. It then returns "Too Many Arguments in Command line" for each of the remaining files in the directory.

This file works perfectly fine on other systems with the same operating system.

It worked on my system until I re-ran it and did not delete the output file first. That caused new.csv.tmp to be produced in the directory and not the final "new.csv", as it couldn't rename it.

Does anyone know what happened? I have tried restarting, deleting everything and starting from scratch. It seems permanently broken on this particular system.

Some searching found that the more command could be at fault. This question is similar.

double-beep
  • 5,031
  • 17
  • 33
  • 41
dtech
  • 3
  • 1
  • 4
  • 1
    Sorry, my crystal ball is failing again, so I can't see the files in your disk, nor the exact Batch file you use, nor the error message... You could remove the `@echo off` line to have more information. But if you don't post more data on this problem, then we just can guess... – Aacini Mar 01 '19 at 21:23
  • I linked the file I am using. I also explained the exact error message returned. The files are all standard CSV files, Like I said, this works perfectly fine on other systems. It's like once the output file was already there, the batch file couldn't over write it and injected some sort of temporary memory of that happening for the rest of the runs I attempted to make. I also started over, from scratch (This worked fine until the output file was not deleted.) And it still doesn't work. – dtech Mar 06 '19 at 19:50

1 Answers1

0

I have before experienced an issue similar to this.

I recall that the method I used, which seemed to have resolved it, was to use the actual syntax from the command help, (note the STDIN redirection):

MORE [/E [/C] [/P] [/S] [/Tn] [+n]] < [drive:][path]filename

Like this:

@SetLocal & Set "PATHEXT="
@"%__AppDir__%where.exe" /Q .:"*.csv" || GoTo :EOF
@Set "_=1" & (  For /F Delims^=^ EOL^= %%G In (
        '""%__AppDir__%where.exe" /F .:"*.csv""')Do @If Defined _ (
        More 0< %%G & Set "_=")Else More +1 0< %%G) 1> "new.tmp"
@EndLocal & Ren "new.tmp" "new.csv"

Alternatively you could try the other shown syntax, (You seem to be using this syntax but without the /E option):

MORE /E [/C] [/P] [/S] [/Tn] [+n] [files]

Like this:

@SetLocal & Set "PATHEXT="
@"%__AppDir__%where.exe" /Q .:"*.csv" || GoTo :EOF
@Set "_=1" & (  For /F Delims^=^ EOL^= %%G In (
        '""%__AppDir__%where.exe" /F .:"*.csv""')Do @If Defined _ (
        More /E %%G & Set "_=")Else More /E +1 %%G) 1> "new.tmp"
@EndLocal & Ren "new.tmp" "new.csv"
Compo
  • 36,585
  • 5
  • 27
  • 39
  • First example returned the same results I was getting(didn't work) Your second example worked perfectly, Thank you! – dtech Mar 06 '19 at 19:57