Reputation:
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?
Upvotes: 9
Views: 7639
Reputation: 21
This:
for /r %a in (.) do @if exist "%~fa*.c" echo %~fa
works for current directory but it doesn't if you specify in which directory you would like to have result:
for /r %a in ('F:\dir\one') do @if exist "%~fa*.c" echo %~fa
it just hangs. I tried 'F:\dir\one' and "F:\dir\one" and 'F:\dir\one\' and "F:\dir\one\"
Upvotes: 0
Reputation: 70923
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
Upvotes: 9