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?

3
  • 3
    You need to escape the PIPE. ^|
    – Squashman
    Commented Oct 12, 2016 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
    Commented Oct 12, 2016 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
    Commented Oct 12, 2016 at 12:48

1 Answer 1

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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.