Jump to content

Directory List - List Only Non Matching Items


Recommended Posts

Hello there,

I want to do a directory listing and then echo only the directories

that do not match the list i provide... i have been working with the

following code, but i have been unable to get the right syntax... help

pls.

@echo off
cls
set TmpPath=thetmp
set tlist="sub1" "sub2" "sub 5" "sub 8" "sub 9"
rem for /f "usebackq delims= tokens=1,2*" %%i in (`%twant%`) do if /i
NEQ %%i echo %%i

call:test "sub1"

:test
for /f "usebackq delims= tokens=1,2" %%i IN (`dir /ad /b
"%TmpPath%\%~1"`) DO IF /i "%%i" NEQ "%~1" echo %%i

I have thetmp directory setup and then under that folder i have sub1 -

15. The final cost would then list all folder accept for sub1,sub2,sub

5,sub 8 and sub9

This works well below, however i am having problems with checking against my list.

for /f "usebackq delims= tokens=1,2" %%i IN (`dir /ad /b
"%TmpPath%\%~1"`) DO IF /i "%%i" NEQ "%~1" echo %%i

all responses very appreciated :)

Link to comment
Share on other sites


We really have to stop meeting this way.

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cls
set TmpPath=.
set tlist="sub1" "sub2" "sub 5" "sub 8" "sub 9"
SET fulllist=
for /d %%i IN (*) DO set fulllist=!fulllist! "%%i"
for %%j IN (%tlist%) do call set fulllist=%%fulllist:%%j=%%
for %%k IN (%fulllist%) DO echo %%~k

Link to comment
Share on other sites

We really have to stop meeting this way.

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cls
set TmpPath=.
set tlist="sub1" "sub2" "sub 5" "sub 8" "sub 9"
SET fulllist=
for /d %%i IN (*) DO set fulllist=!fulllist! "%%i"
for %%j IN (%tlist%) do call set fulllist=%%fulllist:%%j=%%
for %%k IN (%fulllist%) DO echo %%~k

Ice you are right we will have to stop meeting this way :)

The code works well - couple of questions...

1. If i want to add as a default say "sub0" but i don't want to have it in tlist var (want to have it in the code as default) where and how would i put it?

2. I have been playing with this code below? Do you think that would be a better "cleaner" option and if so, any idea on how i would incorporate the list?

DIR "%TmpPath%" /AD /B | FINDSTR /R /V /I /C:"Common Files" /C:"sub0" /c:"sub1" /c:"sub2" /c:"sub 5" /c:"sub 8" /c:"sub 9"

So in this i have "common files" and "sub0" that will always been there and the rest will be variable based on the contents of %tlist%

Thanks very much for all you help - it has been invaluable!

Link to comment
Share on other sites

To add defaults: (See second FOR statement)

@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cls
set TmpPath=.
set tlist="sub1" "sub2" "sub 5" "sub 8" "sub 9"
SET fulllist=
for /d %%i IN (*) DO set fulllist=!fulllist! "%%i"
for %%j IN ("SUB0" "COMMONFILES" %tlist%) do call set fulllist=%%fulllist:%%j=%%
for %%k IN (%fulllist%) DO echo %%~k

Your way is cleaner but harder to pass the list: (one way)

set tlist=/c:"sub1" /c:"sub2" /c:"sub 5" /c:"sub 8" /c:"sub 9"
DIR /AD /B | FINDSTR /R /V /I /C:"Common Files" %tlist%

another way: (limited to 9 sub directories)

set tlist=/c:"sub1" /c:"sub2" /c:"sub 5" /c:"sub 8" /c:"sub 9"
call:continue %tlist%
goto:end
:continue
DIR /AD /B | FINDSTR /R /V /I /C:"Common Files" %1 %2 %3 %4 %5 %6 %7 %8 %9
:end

One last option:

setlocal ENABLEDELAYEDEXPANSION
set tlist="sub1" "sub2" "sub 5" "sub 8" "sub 9"

for %%j IN ("SUB0" "COMMONFILES" %tlist%) do set switchlist=!switchlist! /C:%%j
DIR /AD /B | FINDSTR /R /V /I /C:"Common Files" %switchlist%

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...