• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 982
  • Last Modified:

Batch For loop

I am trying to do a simple batch FOR loop, but I can't figure out how to use a | in the command.

For instance,

FOR /F %G IN ('dir /b') DO echo %G    works

however

FOR /F %G IN ('dir /b | findstr /v xml') DO echo %G    doesn't not work
(| was unexpected at this time.)


I need to do a directory listing but exclude at least one specific file from this loop.  If I run: (dir /b | findstr /v xml) then I get the desired list of files; however, I can't figure out how to use it in the FOR loop
0
xiaoyunwu
Asked:
xiaoyunwu
1 Solution
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
Escape it with ^
FOR /F %G IN ('dir /b ^| findstr /v xml') DO echo %G
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now