0

I am attempting to store the return of a dir command into a variable. So far all I've found requires a for /f loop. This call is made from within another for /f loop and I am having issues with it. Here are snippets for the relevant parts of the code:

set "list=list.txt"
setlocal enabledelayedexpansion

for /f "tokens=*" %%D in (%list%) do (
     set "path_to=%%D"
     ...
     ...
     ...
     for /f "delims=" %%Z in ('dir /b "%path_to%\..\..\.." | find /c /v ""') do (echo %%Z)
)

I am using %path_to% instead of !path_to! because the variable is outside of this second for loop.

  • 1
    `...because the variable is outside of this second for loop` - it is still within the outer `for` loop (where it was defined) and therefore must be delay-expanded. – Stephan May 17 '22 at 17:37

1 Answers1

1

You have to escape pipe with carret ^| if pipe is used in subject of FOR loop. Pipe is a special character in batch files.

user2956477
  • 1,208
  • 9
  • 17