Code in Command prompt doesn't work in batch file

女生的网名这么多〃 提交于 2020-02-06 04:55:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!