Experimenter
Experimenter

Reputation: 167

List files not containing certain string in cmd

With the below code, I'm trying to list files from all folders and subdirectory which does not have a string fontIndex but it does not list anything nor any error.

for %a in ("dir /s *.*") do @findstr "fontIndex" "%a" >nul || echo %a

Upvotes: 1

Views: 3526

Answers (1)

Magoo
Magoo

Reputation: 80033

Try

findstr /i /v /m /L /s "FontIndex" *.*

/i for case-insensitive
/v not-match
/m filename only
/L literal
/s and subdirectories

Your code does not work because the dir/s output is not a list of filenames-only - that would be dir /s /b /a-d and you're getting no output because the >nul disposes of the output (send it to oblivion).

To find files that contain "Fontindex" but not "Fontindex1" (where 1 may ve any alphameric, use

findstr /i /m /R /s "FontIndex[^0-9a-z]" *.*

That is, /R ("regular expression") specified to be Fontindex followed immediately by ^ NOT the [group of characters, where - means range]

I didn't test the /v version as the valid/invalid combinations were simply too bothersome for me to evaluate.

Upvotes: 4

Related Questions