Batch script with for loop and pipe

前端 未结 4 486
小鲜肉
小鲜肉 2020-12-03 02:49

I would like all the csv files in a directory which filename does not contain word \"summary\". Inside the command prompt I can type the following command

di         


        
4条回答
  •  孤街浪徒
    2020-12-03 03:23

    You need to escape the | character to prevent its being interpreted at the time of parsing the loop command. Use ^ to escape it:

    FOR /f "delims=" %%A in ('dir /b "my_dir\*.csv" ^| find /V "summary"') do (
    rem do what you want with %%A here
    )
    

    Once escaped, the | becomes part of the '-delimited string. It is only interpreted as a special symbol when that string is parsed separately from the loop, as a "sub-command", according to the syntax. And that is done after parsing the loop.

提交回复
热议问题