问题描述
当我在命令提示符下执行它时,下面的代码实现了我想要的,但是当我将其放入.bat文件并尝试执行它时,却没有做到:
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!
推荐答案
在批处理文件中-与命令提示符相反- for
变量需要两个 %%符号,例如 %% a
.
In batch files - as opposed to at the command prompt - for
variables require two %% signs, e.g. %%a
.
要在执行命令时关闭命令的回显,请将以下行放在批处理文件的顶部: @echo off
To turn off echoing of commands as they're being executed, place the following line at the top your batch file: @echo off
请注意,在 @
之前加前缀是抑制命令回显的一种特殊方法.在这种情况下,它用于防止 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.
这篇关于命令提示符中的代码不适用于批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!