Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In cmd how can I list folders that contain files with a specific extension?

Using just the command prompt or a batch script, I would like to look inside my current directory and all subdirectories for folders containing a specific filetype.

So, example:

Say I am in directory F:\dir\one\, and F:\dir\one\ looks like this:

F:\dir\one\
|
+--F:\dir\one\two\
|  |
|  +--file.c
|
+--F:\dir\one\three\
|  |
|  +--work.py
|  |
|  +--F:\dir\one\three\four\
|  |  |
|  |  +--file2.c

And I ran my command/script looking for *.c files, I would expect an output of

>F:\dir\one\two
>F:\dir\one\three\four

because those folders contain *.c files.

How could I do this?

like image 519
theonlygusti Avatar asked Sep 16 '14 19:09

theonlygusti


1 Answers

To be run from command line. For batch files, percent signs need to be escaped, replacing % with %%

for /r %a in (.) do @if exist "%~fa\*.c" echo %~fa
like image 130
MC ND Avatar answered Nov 15 '22 07:11

MC ND