{"id":4551,"library":"glob2","title":"glob2","description":"glob2 is an extended version of Python's built-in `glob` module, designed to offer enhanced globbing capabilities. Key features include the ability to capture patterns matched by glob expressions and a recursive `**` wildcard syntax, akin to bash's globstar. The current version is 0.7. The project has seen no active development since 2019, as many of its core functionalities, particularly recursive globbing, have been integrated into Python's standard `glob` module since Python 3.5.","status":"deprecated","version":"0.7","language":"en","source_language":"en","source_url":"https://github.com/miracle2k/python-glob2/","tags":["file system","globbing","wildcards","recursive search","pattern matching"],"install":[{"cmd":"pip install glob2","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The primary way to import the library and access its functions like `glob2.glob()` and `glob2.iglob()`.","symbol":"glob2","correct":"import glob2"}],"quickstart":{"code":"import glob2\nimport os\n\n# Create some dummy files and directories for demonstration\nos.makedirs('src/media/mp3', exist_ok=True)\nwith open('src/fs.h', 'w') as f: f.write('// fs.h')\nwith open('src/media/mp3.h', 'w') as f: f.write('// mp3.h')\nwith open('src/media/mp3/frame.h', 'w') as f: f.write('// frame.h')\nwith open('src/main.py', 'w') as f: f.write('# main.py')\n\n# Example 1: Recursive globbing with '**'\nprint('All header files:')\nall_header_files = glob2.glob('src/**/*.h')\nfor f in all_header_files:\n    print(f)\n\n# Example 2: Capturing patterns (with_matches=True)\n# This example requires a pattern that defines capture groups, e.g., project-(.*).zip\n# For demonstration, let's assume we have files like 'binaries/project-v1.0.zip'\nos.makedirs('binaries', exist_ok=True)\nwith open('binaries/project-v1.0.zip', 'w') as f: f.write('zip content')\nwith open('binaries/project-v2.1.zip', 'w') as f: f.write('zip content')\n\nprint('\\nProject versions (captured patterns):')\nfor filename, (version,) in glob2.iglob('./binaries/project-*.zip', with_matches=True):\n    print(f'{filename}, version: {version}')\n\n# Clean up dummy files and directories\nimport shutil\nshutil.rmtree('src', ignore_errors=True)\nshutil.rmtree('binaries', ignore_errors=True)","lang":"python","description":"This quickstart demonstrates `glob2`'s main features: recursive globbing using `**` to find all header files within a directory and its subdirectories, and capturing parts of filenames using `with_matches=True`."},"warnings":[{"fix":"Prefer `glob.glob(..., recursive=True)` from the standard library or `Path.glob()` and `Path.rglob()` from `pathlib`.","message":"The primary features of `glob2`, specifically recursive globbing with `**`, have been integrated into Python's standard `glob` module since Python 3.5. `pathlib` also provides robust globbing functionality. There is generally no compelling reason to use `glob2` in modern Python versions.","severity":"deprecated","affected_versions":"< Python 3.5 for 'standard glob' limitations, all versions for 'glob2' redundancy"},{"fix":"Migrate to `glob` or `pathlib` from Python's standard library for continued support and maintenance.","message":"The `glob2` library is no longer actively maintained. The last release was in 2019, and the last code push was over 4 years ago. This means it may not be compatible with newer Python versions or address new security vulnerabilities or bugs.","severity":"breaking","affected_versions":"0.7 and earlier"},{"fix":"Ensure `**` is isolated between path separators (e.g., `dir1/**/dir3/*.txt`). Adjust patterns (e.g., `*/**/*.py`) if you want to exclude immediate children of the starting directory when using `**`.","message":"The recursive wildcard `**` in `glob2` (and standard `glob`) must appear as a standalone directory element. For example, `src/**/*.h` is correct, but `src/**h` will not have the desired recursive effect. Additionally, `**/*.py` will match Python files in the current directory (`.`), if not intended, use `*/**/*.py` to exclude the current directory.","severity":"gotcha","affected_versions":"All versions of glob2"},{"fix":"Use raw strings (e.g., `r'C:\\Users\\...'`) or forward slashes (e.g., `'C:/Users/...'`) for path patterns on Windows to avoid issues with backslash escapes.","message":"When using Windows file paths, backslashes are interpreted as escape characters. This can lead to incorrect path matching or errors.","severity":"gotcha","affected_versions":"All Python versions on Windows"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}