简体   繁体   中英

Why does execution in shell give different result that execution in batch script?

I'd like to list all .csv files in a directory and its subdirectories. It works nicely when I run this in the cmd terminal:

for /f %a in ('dir /b /s *.csv') do (echo %a)

When I put the same line of code into an (otherwise empty) text file (.cmd) and run that .cmd file, it outputs a blank line, but does not list any files.

Why does it make a difference whether I put the commands into a script or enter them directly (in one go) in the terminal?

Thinking it might be a delayed expansion issue, I also tried for /f %a in ('dir /b /s *.csv') do (echo !a!) , but this doesn't list the files either.

Any ideas?

将批处理文件中的百分比符号加倍!

for /f %%a in ('dir /b /s *.csv') do (echo %%a)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM