1

I can use dir /s /b *.Tests.*.dll to recursively find all files that match that pattern, but I need to also find them only if they are in \bin\Debug\ instead of \obj\Debug\ or \bin\Release.

So I tried this command:

dir /s /b Tests\Unit\*\Debug\bin\*.Tests.*.dll

But it fails with The filename, directory name, or volume label syntax is incorrect.

I couldn't find any previous SO question that addresses this problem but if one exists please point it to me.

Is there any way to achieve the desired result (apply filter on entire path)? My intent is to use the list to run NUnit on each unit test assembly in my project under jenkins using this command from Use NUnit Console Runner to run all tests under a folder

for /f %%f in ('dir .\test\ /b /s *.Test.dll') do nunit-console /nologo /noshadow /framework:net-4.0 /xml:.\test\TestResults.xml "%%f"

On linux I would have used ls -r ... | grep ... | xargs ... and I'm trying to achieve something similar here.

I only need to apply this additional filter on the parent folders as well. If it's not possible I'll have to use PowerShell.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • I don't think `dir` works with wildcard(`*`), except the filename or file extension –  Jul 20 '17 at 14:49
  • Also, in `*.Tests.*.dll`, do you mean `*.Tests. *.dll`? Space makes a big difference. The first one search can match files like: a.Test.b.dll(**one file!**), the second matches. a.tests, b.dll –  Jul 20 '17 at 14:51
  • Uhmm. By the way, I don't understand what folders and files does your script wants to match. The word `only` in the first sentence confused me. –  Jul 20 '17 at 14:54
  • I've written `*.Tests.*.dll`. Where do you see the space? – sashoalm Jul 20 '17 at 15:00
  • oh welp. I was sleepy... misread it, sorry :( –  Jul 20 '17 at 15:00
  • Uhm.. Can you please add the folder/file structure and the expected result? –  Jul 20 '17 at 15:04
  • Never mind, I found a solution which I'll post. – sashoalm Jul 20 '17 at 15:17

2 Answers2

1
FOR /d %%a IN ("%sourcedir1%\*") DO DIR /s /b "%%~a\%sourcedir2%\*.exe" 2>nul

where sourcedir1 is the part of the required path before the \*\ and sourcedir2 the part after.

simply assign each dirname in turn to %%a and use that as the start point for the second dir

Magoo
  • 77,302
  • 8
  • 62
  • 84
0

I found DOS batch script with for loop and pipe, and using the idea there I constructed this command:

for /f %f in ('dir /s /b Tests\Unit ^| findstr \\bin\\Debug\\.*\.Tests\..*\.dll$"') do echo %f

No I only need to replace %f with %%f for batch files, and I can replace echo %f with the command to run nunit.

sashoalm
  • 75,001
  • 122
  • 434
  • 781
  • In the first sentence, do you mean `Windows batch script` instead of `DOS batch script`? `DOS` is an old operating system. `CMD` is your command prompt. –  Jul 21 '17 at 00:54
  • I mean a windows batch script. – sashoalm Jul 21 '17 at 07:26