digitalmars.D.learn - Can I skip sub directories with file.dirEntries() ?
- Ky-Anh Huynh (14/14) Sep 27 2017 Hi,
- Nicholas Wilson (16/31) Sep 27 2017 I'd just use dirEntries with SpanMode.shallow in combination with
- Ky-Anh Huynh (10/24) Sep 27 2017 Thank you Nicolas. It's a good idea.
Hi,
Can I have a `break` option when using `dirEntries()` (similar
to `break` in a loop)? I want to study sub-directories but if any
sub-directory matches my criteria I don't to look further into
their subdirectories
```
<working-dir>
A/ -> matches criteria, stop here, go to next directory (B)
B/ -> doesn't match criteria, will look at its
sub-directories (BX, BY,...)
BX
BY
```
Thanks a lot
Sep 27 2017
On Wednesday, 27 September 2017 at 09:00:55 UTC, Ky-Anh Huynh
wrote:
Hi,
Can I have a `break` option when using `dirEntries()` (similar
to `break` in a loop)? I want to study sub-directories but if
any sub-directory matches my criteria I don't to look further
into their subdirectories
```
<working-dir>
A/ -> matches criteria, stop here, go to next directory
(B)
B/ -> doesn't match criteria, will look at its
sub-directories (BX, BY,...)
BX
BY
```
Thanks a lot
I'd just use dirEntries with SpanMode.shallow in combination with
filter either in a loop or a recursive function like below.
void foo(string path = "path")
{
foreach(e;
dirEntries(path,SpanMode.shallow).filter!(myCritreia(paramters)))
{
if (e. isDir)
foo(e.name); // recurse
// do other stuff
}
}
you will loop over all subdirs of "path" that satisfy
`myCritreia`.
Sep 27 2017
On Wednesday, 27 September 2017 at 10:05:34 UTC, Nicholas Wilson
wrote:
I'd just use dirEntries with SpanMode.shallow in combination
with filter either in a loop or a recursive function like below.
void foo(string path = "path")
{
foreach(e;
dirEntries(path,SpanMode.shallow).filter!(myCritreia(paramters)))
{
if (e. isDir)
foo(e.name); // recurse
// do other stuff
}
}
you will loop over all subdirs of "path" that satisfy
`myCritreia`.
Thank you Nicolas. It's a good idea.
PS: With Linux find command, the thing can be done easily with
`-prune` option:
```
find . -iname node_modules -prune
```
Without `-prune` option, there are a lot of unnecessary sub
directories...
Sep 27 2017








Ky-Anh Huynh <saigon example.net>