1

I'm new to batch scripting and trying to find a way to iterate through all files in a folder and print the names of all files who start with Test_ and end with .py (i.e python files)

I'm stuck here:

@echo off
for /r %%f in (*) do (
    echo %%f | findstr /r "^Test_[.]*\.py$"
)
pause

But this doesn't echo anything to screen. Can you help?

Thanks,

Noam

Noam
  • 1,469
  • 2
  • 23
  • 49

2 Answers2

1

Try "Dir /b "Test_*.py""

Also you can do "Dir /b "C:\path\Test_*.py""

Mark Deven
  • 530
  • 1
  • 8
  • 21
1

You may find the Where command useful:

Where/R . "Test_?*.py"
Compo
  • 34,184
  • 4
  • 22
  • 36
  • if I already know there will be only exactly one match, is it possible to directly asign the result to a variable or would I still need a `for` loop? I'm aksing because I once had [this question](https://stackoverflow.com/questions/47450531/batch-write-output-of-dir-to-a-variable) but didn't know `Where` exists and I think it would simplify my code a lot – derHugo Jul 18 '19 at 10:56
  • I'm sorry @derHugo, I'm not in the habit of providing free support to members based upon a comment made to a 20 month old, not accepted answer. – Compo Jul 18 '19 at 11:23