问题
The code below does what I want when I execute it in the command prompt but not when I put it in a .bat file and try to execute it:
for /f %a in ('dir /b *.csv') do for /f "tokens=*" %b in (%a) do echo %b,%a >> all.csv
What am I missing. Also is there a way to have it do exactly what it does without displaying every step in the loop in the command prompt window. Excuse me I am a newbie!
回答1:
In batch files - as opposed to at the command prompt - for
variables require two %% signs, e.g. %%a
.
To turn off echoing of commands as they're being executed, place the following line at the top your batch file: @echo off
Note that prepending @
is an ad-hoc way of suppressing command echoing; in this case it is used to prevent echo off
itself from being echoed.
来源:https://stackoverflow.com/questions/23070963/code-in-command-prompt-doesnt-work-in-batch-file