haltcase/glob

walkGlobKinds(".", includeDirs=true) excludes "." ; needs to be documented: inconsistent with `python glob` and unix `find .`

timotheecour opened this issue · 8 comments

walkGlobKinds(".", includeDirs=true) excludes "." ; needs to be documented: inconsistent with `python glob` and unix `find .`

Looks like find/unix glob expands the lone . into **/*? That's consistent with the expandDirs option I guess, so which route do we want to go - update docs or match unix?

probably best is to add a flag: includeTopLevelDir (false by default)

Hmm actually I just tested this out on Windows and in WSL bash — glob does the same thing unix's find does and expands "." and ".." into their directories when expandDirs == true (default).

honestly it doesn't matter which default is used (clearly different tools use different convention here) so long there's an option (eg includeTopLevelDir) ; there are valid use cases for both options

@timotheecour then I'm going to close this one as I consider it working as intended — it's just a directory same as any other so I don't see why it should be treated differently by expandDirs.

@citycide

glob does the same thing unix's find does

sorry I don't follow. on linux:

tree
.
└── foo
    └── bar
find foo
foo
foo/bar
echo toSeq(glob.walkGlobKinds("foo", includeDirs=true)).join("\n")
(path: "foo/bar", kind: pcDir)

echo toSeq(glob.walkGlob("foo", includeDirs=true)).join("\n")
foo/bar

so glob doesn't return the same as unix's find, as it misses "foo"

/cc @citycide could we re-open this?

actually both python glob.glob and unix find return top-level dir:
find bar
bar
bar/bar2
bar/bar2/bar3
bar/f1.txt

glob.glob('bar/**', recursive=True)
Out[17]: ['bar/', 'bar/bar2', 'bar/bar2/bar3', 'bar/f1.txt']

but not your library's glob:

echo toSeq(glob.walkGlob("bar/**", includeDirs=true)).join("\n")
bar/bar2
bar/f1.txt
bar/bar2/bar3

If foo is a directory you'll have to use includeDirs = true as documented to include it in the results.

I am using includeDirs = true

NOTE: just changed the title to add includeDirs=true in query

NOTE: for D, top-level dir is not included:
rdmd --eval 'dirEntries("bar", SpanMode.depth).writeln'
["bar/bar2/bar3", "bar/bar2", "bar/f1.txt"]

based on these, I still recommend introducing a flag includeTopLevelDir ; both behaviors are useful

Oh well this is very different from what I thought the issue was, a more descriptive OP would have been useful 😆 .

I don't think this needs an option but the directory itself should be included.