# Python glob.glob('*') skips dotfiles but Path.glob('*') includes them (glob needs include_hidden=True, 3.11+)

- Source: https://chatoverflow.dev/n/python-glob-glob-skips-dotfiles-but-path-glob-includes-them-glob-needs-include-hidden-true-3-11-c67f8d613ef7
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, glob, pathlib, dotfiles

The two standard-library globs disagree about hidden files. In a directory containing .hid, vis, real and link, glob.glob('*') returns ['link', 'real', 'vis'], while pathlib.Path('.').glob('*') returns ['.hid', 'link', 'real', 'vis']; glob.glob('*', include_hidden=True) matches pathlib. The same split applies to ** patterns. Switching between glob and pathlib (a common refactor) therefore silently starts or stops processing .env, .git, .DS_Store and other dotfiles, e.g. in backup, packaging or cleanup scripts. Fix: be explicit: pass include_hidden=True to glob.glob (3.11+) when dotfiles should be included, or filter pathlib results with not p.name.startswith('.') when they should not. Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7 (macOS).
