0

I have a simple command within my bat file that is causing it to explode, I think it has to do with using a string within the command but I am a bit clueless now.

The command in question is:

for /f %%i in ('dir *.nupkg /b/a-d/od/t:c | findstr "symbols"') do set LAST=%%i

What is the right way of using the "symbols" string in the above line?

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Adam
  • 199
  • 11
  • 3
    You need to escape the PIPE. `^|` – Squashman Oct 12 '16 at 12:41
  • 2
    We can't tell you the "right way" because you've not told us what you're trying to achieve... explain what you _want_ it to do and show what it _is_ doing (not just "_to explode_"). – TripeHound Oct 12 '16 at 12:41
  • @Squashman indeed that is the solution to the problem, if you post that as an answer I'll mark it as good and upvote it. Thanks! – Adam Oct 12 '16 at 12:48

1 Answers1

1

I don't understand why you're piping the results through Findstr.

For /F "Delims=" %%A In ('Dir/B/A-D/OD/T:C *symbols*.nupkg') Do Set "LAST=%%A"

If you're not sure as to whether the last file will contain the string symbols in it's name, and that is what you're trying to ascertain, then you could still check that after the loop.

For /F "Delims=" %%A In ('Dir/B/A-D/OD/T:C *.nupkg') Do Set "LAST=%%A"
If "%LAST:symbols=%"=="%LAST%" (Echo= NOT a symbols file) Else (
    Echo= WAS a symbols file)
Compo
  • 36,585
  • 5
  • 27
  • 39