Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

How use DIR to find directories

Jun
784
6
The Help says that FFIND is soon to be deprecated. I've been using FFIND to find files and directories. Apparently, I should use DIR instead. But, I can't get DIR to show a directory unless there is something in it. See below. Also, neither won

C:\Junk>ffind /b /s Bar
C:\Junk\Foo\Bar

C:\Junk>dir /b /s /a:d Bar

C:\Junk>ver

TCC 32.10.21 x64 Windows 10 [Version 10.0.19045.4291]
 
The Help says that FFIND is soon to be deprecated. I've been using FFIND to find files and directories. Apparently, I should use DIR instead. But, I can't get DIR to show a directory unless there is something in it. See below. Also, neither won

C:\Junk>ffind /b /s Bar
C:\Junk\Foo\Bar

C:\Junk>dir /b /s /a:d Bar

C:\Junk>ver

TCC 32.10.21 x64 Windows 10 [Version 10.0.19045.4291]

If you want to find subdirectories by name, I think you have to use a wildcard. If you want to find that one specific name — BAR — then you'll need a wildspec which matches only that one name:

Code:
dir /b /s /ad Ba[r]
 
Or continue using FFIND if that works the way you want. It may be 'deprecated', but I doubt that it will be removed anytime soon. It just won't get any improvements.
 
Nothing I try works the way I want it to. I want to search the current directory and its subdirectories for a file or a directory or either. I want to be able to include * in the file/directory name. In the following example, there are two directories named Foo. So, the result should be just those two directories.

C:\Junk>dir

Volume in drive C is unlabeled Serial number is c070:3990
TCC: (Sys) The system cannot find the file specified.
"C:\Junk\*"
0 bytes in 0 files and 0 dirs
184,624,996,352 bytes free

C:\Junk>mkdir Foo

C:\Junk>mkdir /s Bar\Foo

C:\Junk>mkdir NoFoo

C:\Junk>dir /s /a:d /b Foo

C:\Junk>ffind /s Foo

0 files

C:\Junk>everything %_cwd\Foo
C:\Junk\Foo

C:\Junk>everything %_cwd\*Foo
C:\Junk\Foo
C:\Junk\Bar\Foo
C:\Junk\NoFoo
 
Code:
C:\Junk>tree

C:\Junk
├──Bar
│  ├──Foo
│  └──Foolish Young Love
├──Baz
│  └──Egg Foo Young
├──Foo
├──FooNot
└──NoFoo

C:\Junk>dir /s /ad /b foo[]
C:\Junk\Foo
C:\Junk\Bar\Foo

C:\Junk>ffind /s /ad /m foo[]
C:\Junk\Foo
C:\Junk\Bar\Foo

C:\Junk>
 
I suppose that's clever, but not user friendly. For an exact match, I have to add []. But, if I include a wild card, then I have to not add []. But, if I search for files, then [] is not needed. This sure seems like a bug.
 
I suppose that's clever, but not user friendly. For an exact match, I have to add []. But, if I include a wild card, then I have to not add []. But, if I search for files, then [] is not needed. This sure seems like a bug.

I'd say it's a deliberate feature, because CMD.EXE behaves the same way and TCC is intended to be compatible. Well, except that CMD.EXE doesn't support the brackets.
 
@David Marcus

Ah, yep - of course - I had as Test "NoFoo" THEN it works. Of course that does not work in your case, sorry about that.

In your case it would be:

Code:
dir /s /a:d /b *Foo
pdir /s /a:d /b *Foo
ffind /s /a:d *Foo

Note that ffind also requires "/a:d" param ...
 
I even found another which should work ... so ALL new suggestions would be:
Code:
dir /s /a:d /b *Foo
pdir /s /a:d /b *Foo
ffind /s /a:d *Foo
everything /d /p "c:\Junk\*Foo"

Or if you are in the related directory already:
Code:
everything /d /p "%cd%\*Foo"
 
I even found another which should work ... so ALL new suggestions would be:
Code:
dir /s /a:d /b *Foo
pdir /s /a:d /b *Foo
ffind /s /a:d *Foo
everything /d /p "c:\Junk\*Foo"

Or if you are in the related directory already:
Code:
everything /d /p "%cd%\*Foo"
These don't work. They find NotFoo in addition to Foo. If I am searching for Foo, I want to find things named Foo.
 
Yes, you are right, it can't handle NotFoo and FooNot at the same time ...

PS: I thought it was for a "fixed" scenario where not both cases have to be covered ...
 
Last edited:
How about using a regular expression?

Code:
v:\test> tree

V:\test
├──1abc
│  ├──1abc
│  ├──abc
│  └──abc1
├──abc
│  ├──1abc
│  ├──abc
│  └──abc1
└──abc1
   ├──1abc
   ├──abc
   └──abc1

v:\test> dir /f /s /a:d ::^^abc$
V:\test\abc
V:\test\1abc\abc
V:\test\abc\abc
V:\test\abc1\abc
 
I reckon the syntax would be the same. /F and /S (maybe other switches) can vary according to your needs. Just put the directory name ...

Code:
dir /f /s /a:d ::^^HERE$
or
Code:
dir /f /s /a:d ::"^HERE$"  (quoting would be needed for names with spaces)

The BOL and EOL anchors (^ and $) force the string between them to be exact (except for case) ... there are no implied wildcards. At the moment that seems intuitive and easy enough. It probably won't be so intuitive or easy after enough time passes. And an example of it probably won't make it into the help.
 
I reckon the syntax would be the same.
The syntax is different, so * doesn't work as a wild card. Charles's hack is simpler. I suppose I could write a btm file to fix the cases that don't work as expected. I only realized recently that the obvious syntax doesn't always work.
 
What about "es" (the command line variant of "everything")?

Code:
D:\_Tests\Junk
├  1Foo
├  1Foo.txt
├──Foo
├  Foo.txt
├──Foo1
├──FooNot
│  └──Foo
└──NotFoo

Code:
es /ad -w -p %cd% Foo

resp.
Code:
"C:\Program Files\JPSoft\TCMD32\es.exe" /ad -w -p %cd% Foo

Result is:
Code:
D:\_Tests\Junk\Foo
D:\_Tests\Junk\FooNot\Foo

It SEEMS to work ...
 
It SEEMS to work ...
I don't know. I think that if you had a directory D:\_Tests\Junk\Foo\FooNot it would be listed among the results. That's because you said -p (also look for matches in the path).
 
Last edited:
New try ;-)

Code:
D:\_Tests\Junk
├  1Foo
├  1Foo.txt
├──Foo
│  ├  1foo.txt
│  ├  foo.txt
│  ├  foo1.txt
│  ├──FooNot
│  └──NotFoo
├  Foo.txt
├──Foo1
├──FooNot
│  └──Foo
└──NotFoo
   ├──FooNot
   └──NotFoo

"C:\Program Files\JPSoft\TCMD32\es.exe" /ad -w %cd% Foo
D:\_Tests\Junk\Foo
D:\_Tests\Junk\FooNot\Foo
 
Last edited:

Similar threads

Back
Top