Daniel F.
Daniel F.

Reputation: 69

skip on more then one specific folders in FOR loop

With some help I eventually managed to find a FOR loop that search the computer for a file that have the same name as the input string. Now my only problem is that I want the for loop to skip two directories instead of just one. Is it even possible?

for %%a in (C D E F G H U W) do (
    for /f "tokens=*" %%b in ('dir /s /b "%%a:\%filename%" ^|findstr /v /i /L /c:"%cd%\directory i want to skip" ') do (
    ---
    ---
    ---
    )
)

I tried this way but it doesn't seem to be working:

for %%a in (C D E F G H U W) do (
    for /f "tokens=*" %%b in ('dir /s /b "%%a:\%filename%" ^|findstr /v /i /L /c:"%cd%\directory i want to skip" ^|findstr /v /i /L /c:"%cd%\ another directory i want to skip" ') do (
    ---
    ---
    ---
    )
)

Upvotes: 2

Views: 57

Answers (2)

Magoo
Magoo

Reputation: 79983

Yes, it is. You can double-up on the c:"..." clause in the findstr or you could construct a file of all of your required exclusions and use this file as a /g:filename, as I advised you in your last question.

Upvotes: 1

evergoo
evergoo

Reputation: 36

What about using /c:"string" twice in the same findstr statement:

 for /f "tokens=*" %%b in ('dir /s /b "%%a:\%filename%" ^|findstr /v /i /L /c:"%cd%\directory /c:"%cd%\ another directory i want to skip" ') do (.....

Upvotes: 0

Related Questions