• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 984
  • 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


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
1 Solution
Lee W, MVPTechnology and Business Process AdvisorCommented:
Escape it with ^
FOR /F %G IN ('dir /b ^| findstr /v xml') DO echo %G
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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