List folders/directories that does NOT contain a specific file

Hi

Is there any way for me to list all directories (paths) that does NOT contain a specific file?
I have access to the command prompt, run a batch file or any other standard windows server 2003 tools. I can also if it is needed use sed, find and xargs (however no other cygwin tool).

I would really much appreciate your help with this!
niklasmoAsked:
Who is Participating?
 
Steve KnightIT ConsultancyCommented:
@echo off
set filetofind=test.txt
cd /d c:\
for /f "tokens=*" %%a in ('dir /ad /b /s') do if not exist "%%a\%filetofind%" echo %%a

This should run down all directories under hte one you specify in the cd command and if the file you specify does not exist then it will echo the foldername to the screen.  That can easily be directed to a file with:

@echo off
set filetofind=test.txt
cd /d c:\
(for /f "tokens=*" %%a in ('dir /ad /b /s') do if not exist "%%a\%filetofind%" echo %%a)> log.txt
notepad log.txt
0
 
Steve KnightIT ConsultancyCommented:
If you want to do it from the command line then this will run from the current directory:

(for /f "tokens=*" %a in ('dir /ad /b /s') do if not exist "%a\filetofind.txt" echo %%a)>log.txt

Steve
0
 
niklasmoAuthor Commented:
Perfect! Thank you for your quick and satisfying answer!
0
 
Steve KnightIT ConsultancyCommented:
No problem, glad it helped!

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.