?
Solved

List folders/directories that does NOT contain a specific file

Posted on 2010-01-05
4
Medium Priority
?
393 Views
Last Modified: 2012-05-08
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!
0
Comment
Question by:niklasmo
  • 3
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 26179544
@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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 26179561
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
 

Author Closing Comment

by:niklasmo
ID: 31672857
Perfect! Thank you for your quick and satisfying answer!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 26179703
No problem, glad it helped!

Steve
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question