Listing folders in CMD which does NOT have a specific subfolder

1

I've an issue where i need to locate all folders on a drive which does NOT have a folder in them called "Arg".. I know how to do it in reverse using DIR, i.e to find all subfolder with a specific name, but as I need the opposite of that.. I rely on superuser wisdom to help Me.

Thanks.

Aryat Mapreh

Posted 2016-02-11T11:29:04.350

Reputation: 41

Answers

1

I think FOR/IF NOT EXIST are your friends, in this case...

For immediate subfolders of the current folder...

for /d %A in (*) do @if not exist "%~fA\Arg\*" echo %~fA

Or recursively, from current folder down...

for /d /r %A in (*) do @if not exist "%~fA\Arg\*" echo %~fA

Or recursively, from a given path...

for /d /r X:\pathto %A in (*) do @if not exist "%~fA\Arg\*" echo %~fA

Conversely...

for /d %A in (*) do @if exist "%~fA\Arg\*" echo %~fA
for /d /r %A in (*) do @if exist "%~fA\Arg\*" echo %~fA
for /d /r X:\pathto %A in (*) do @if exist "%~fA\Arg\*" echo %~fA

In a batch file, you would need to escape the % symbol...

for /d %%A in (*) do @if exist "%%~fA\Arg\*" echo %%~fA
for /d /r %%A in (*) do @if exist "%%~fA\Arg\*" echo %%~fA
for /d /r X:\pathto %%A in (*) do @if exist "%%~fA\Arg\*" echo %~fA

for /d %%A in (*) do @if not exist "%%~fA\Arg\*" echo %%~fA
for /d /r %%A in (*) do @if not exist "%%~fA\Arg\*" echo %%~fA
for /d /r X:\pathto %%A in (*) do @if not exist "%%~fA\Arg\*" echo %~fA

If you're doing it regularly, perhaps a macro...

doskey nosubdir=for /d %A in (*) do @if not exist "%~fA\$*\*" echo %~fA
doskey nosubdirrec=for /d /r %A in (*) do @if not exist "%~fA\$*\*" echo %~fA
...
cd /d x:\pathto
nosubdir Arg
nosubdirrec Arg

jimbobmcgee

Posted 2016-02-11T11:29:04.350

Reputation: 622

0

enter image description here

If you can run recursive dir and redirect its output to a file, then you are halfway through. The rest can be done with the find command that looks for lines that contain or do not contain the given string.

Here I listed my directories into mydirs.lst. First, I looked for directories containing the string "Links", then I did the opposite by using the /v switch.

Gombai Sándor

Posted 2016-02-11T11:29:04.350

Reputation: 3 325

Can you do some sort of diff on the list then to find out the folders which has it and don't? – Aryat Mapreh – 2016-02-11T14:59:11.500