Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do glob.glob and pathlib.Path.glob treat hidden files differently?

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?

like image 396
Aran-Fey Avatar asked Apr 16 '18 17:04

Aran-Fey


1 Answers

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.

like image 64
Aran-Fey Avatar answered Nov 10 '22 10:11

Aran-Fey