List of Folders that do not contain a certain folder at a given depth

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Nate
Posts: 1
Joined: 25 Jan 2018 10:29

List of Folders that do not contain a certain folder at a given depth

#1 Post by Nate » 25 Jan 2018 10:42

I am trying to find the answer to the following question. I have been trying to list the directory trees that do not contain the folder "sample" at a given depth. The depth level will always be the same and I have been able to list all folders that contain the given folder by the following command however I can't seem to figure out how to list the directory trees that don't contain the folder.

Here is the code I am using so far:

Code: Select all

@echo off
pushd e:\tv\
for /f %%a in ('dir /s/b/ad') do (
if /i "%%~na" EQU "sample" echo %%a >>c:\temp.txt
)
Again this code will produce all directory trees that contain the given folder, and will leave out the the ones that don't. If I switch the "EQU" to "NEQ" it will produce a list, but not at the proper depth level.

Example: - this will be my output from the script with "EQU"

Code: Select all

 e:\TV\#\foo\foo\foo\Sample
When I switch the code to "NEQ" it will give me all folders including the ones with that sample folder in it.

I just want to produce a list of directories that do not contain the Sample folder on the 6th folder deep.

Thanks for your help.


Post Reply