13

Consider this folder containing two files:

test/
    foo
    .bar

Calling glob.glob('*') on this folder won't list the hidden .bar file:

>>> glob.glob('test/*')
['test/foo']

But pathlib.Path.glob('*') will:

>>> list(Path('test').glob('*'))
[PosixPath('test/.bar'), PosixPath('test/foo')]

I'd like to know if this is intended or possibly a bug/oversight.


The glob module documentation states that files starting with a dot are special cased:

glob treats filenames beginning with a dot (.) as special cases

Meaning that the result given by glob.glob('*') is intended. But what about pathlib's glob? I couldn't find any relevant information in the docs. Is this the intended behavior? Shouldn't both functions produce the same results?

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
  • The discussion there explains well why dotfiles are returned, but not the inconsistency with glob.glob() - you ca put that down to history. – mdurant Apr 16 '18 at 17:06
  • 1
    @vaultah Oh, nice find. Could I convince you to post that as an answer so you can take my upvote? – Aran-Fey Apr 16 '18 at 17:07
  • You sure aren't easily bribed. What if I throw in a green check mark next to your answer? :P – Aran-Fey Apr 16 '18 at 17:09

1 Answers1

7

As per issue #26096 on the official bug tracker, this difference has been deemed not a bug and is therefore completely intended.

Credits to @vaultah for the find.

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149