I want to make a recursive search with findstr
while excluding folders starting with .
(e.g. .git
, .github
, .ipynb_checkpoints
, etc.).
Based on this answer, I am using
findstr /C:"valid" /N /S *py | findstr /V ".*\"
but returns files in .ipynb_checkpoints
folder. I would like to have a one-line solution.
The findstr /V ".*\"
part is not working because the backslashes seem to be treated in a weird way. Part of the problem is caused by cmd.exe (in PowerShell, it’s a bit different). Using four backslashes (in cmd.exe) will match a single backslash in the input, and it nearly works:
findstr /C:"valid" /N /S *py | findstr /V ".*\\"
Unfortunately, the above will not only omit .ipynb_checkpoints*
but it will also omit lines where the dot is not at the beginning of the line – even if you use /B
.
The following works, using regular expressions:
findstr /C:"valid" /N /S *py | findstr /V /R "^..*\\"
If you use PowerShell, use just two instead of four backslashes:
findstr /C:"valid" /N /S *py | findstr /V /R "^..*\"
3