Reputation: 245
I am trying to locate a file using dir
and findstr
to be able to specify the extension and a pattern in the name.
For this, I use the following command:
for /f %%a in ('dir /b /s *.pm | findstr /i "MyPattern"') do (set "name=%%a")
The question has been mostly answered in here, here and in here.
But none of them applied to my case.
Upvotes: 0
Views: 425
Reputation: 5504
You need to escape the pipe (|
) because it breaks the for
loop just because it is always executed with higher prio. Modify your code like the following:
for /f %%a in ('dir /b /s *.pm ^| findstr /i "MyPattern"') do (set "name=%%a")
and it should work.
Upvotes: 1