Why is an extra file being created in FOR loop of batch program?

前端 未结 3 1372
失恋的感觉
失恋的感觉 2020-12-19 19:30

I\'ve written the following batch file to create multiple files using FOR loop:

@echo off  
cls  
FOR /L %%i IN (1 1 10) DO (  
    echo.> file%%i.txt  
         


        
3条回答
  •  时光取名叫无心
    2020-12-19 19:46

    I don't know why, but when you write ... IN (*.txt) ... in the second for loop, it is trying to find files that are just created within the body of the loop.

    To eliminate that, I would make my filter a bit more specific.

    FOR %%i IN (file??.txt) DO (
    

    I ran this and it creates only 20 files as expected.

提交回复
热议问题