{"id":13424527,"url":"https://github.com/p-ranav/glob","last_synced_at":"2025-04-06T11:10:28.578Z","repository":{"id":40356675,"uuid":"289379729","full_name":"p-ranav/glob","owner":"p-ranav","description":"Glob for C++17","archived":false,"fork":false,"pushed_at":"2024-04-18T01:21:19.000Z","size":303,"stargazers_count":259,"open_issues_count":12,"forks_count":42,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-30T09:09:32.979Z","etag":null,"topics":["cpp11","cpp14","cpp17","cpp17-library","cpp17orlater","file-name","filesystem","filesystem-library","glob","header-only","lightweight","name-matching","pattern-matching","pattern-recognition","recursively-search","single-header","single-header-lib","unix","wildcards"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/p-ranav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-08-21T22:52:03.000Z","updated_at":"2025-03-26T15:09:12.000Z","dependencies_parsed_at":"2024-10-28T16:33:59.769Z","dependency_job_id":null,"html_url":"https://github.com/p-ranav/glob","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Fglob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Fglob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Fglob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-ranav%2Fglob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p-ranav","download_url":"https://codeload.github.com/p-ranav/glob/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247471521,"owners_count":20944158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp11","cpp14","cpp17","cpp17-library","cpp17orlater","file-name","filesystem","filesystem-library","glob","header-only","lightweight","name-matching","pattern-matching","pattern-recognition","recursively-search","single-header","single-header-lib","unix","wildcards"],"created_at":"2024-07-31T00:00:55.634Z","updated_at":"2025-04-06T11:10:28.560Z","avatar_url":"https://github.com/p-ranav.png","language":"C++","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg height=\"90\" src=\"img/logo.png\"/\u003e  \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  Unix-style pathname pattern expansion\n\u003c/p\u003e\n\n## Table of Contents\n\n- [Quick Start](#quick-start)\n  * [Build Library and Standalone Sample](#build-library-and-standalone-sample)\n- [Usage](#usage)\n- [API](#api)\n- [Wildcards](#wildcards)\n- [Examples](#examples)\n  * [Match file extensions](#match-file-extensions)\n  * [Match files in absolute pathnames](#match-files-in-absolute-pathnames)\n  * [Wildcards: Match a range of characters listed in brackets ('[]')](#wildcards-match-a-range-of-characters-listed-in-brackets-)\n  * [Exclude files from the matching](#exclude-files-from-the-matching)\n  * [Wildcards: Match any one character with question mark ('?')](#wildcards-match-any-one-character-with-question-mark-)\n  * [Case sensitivity](#case-sensitivity)\n  * [Tilde expansion](#tilde-expansion)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Quick Start\n\n* This library is available in two flavors:\n  1. Two file version: `glob.h` and `glob.cpp`\n  2. Single header file version in `single_include/`\n* No external dependencies - just the standard library\n* Requires C++17 `std::filesystem`\n  - If you can't use `C++17`, you can integrate [gulrak/filesystem](https://github.com/gulrak/filesystem) with minimal effort.\n* MIT License\n\n### Build Library and Standalone Sample\n\n```bash\ncmake -Hall -Bbuild\ncmake --build build\n\n# run standalone `glob` sample\n./build/standalone/glob --help\n```\n\n### Usage\n\n```cpp\n// Match on a single pattern\nfor (auto\u0026 p : glob::glob(\"~/.b*\")) {                // e.g., .bash_history, .bashrc\n  // do something with `p`\n}\n\n// Match on multiple patterns\nfor (auto\u0026 p : glob::glob({\"*.png\", \"*.jpg\"})) {     // e.g., foo.png, bar.jpg\n  // do something with `p`\n}\n\n// Match recursively with `rglob`\nfor (auto\u0026 p : glob::rglob(\"**/*.hpp\")) {            // e.g., include/foo.hpp, include/foo/bar.hpp\n  // do something with `p`\n}\n```\n\n## API\n\n```cpp\n/// e.g., glob(\"*.hpp\")\n/// e.g., glob(\"**/*.cpp\")\n/// e.g., glob(\"test_files_02/[0-9].txt\")\n/// e.g., glob(\"/usr/local/include/nc*.h\")\n/// e.g., glob(\"test_files_02/?.txt\")\nvector\u003cfilesystem::path\u003e glob(string pathname);\n\n/// Globs recursively\n/// e.g., rglob(\"Documents/Projects/Foo/**/*.hpp\")\n/// e.g., rglob(\"test_files_02/*[0-9].txt\")\nvector\u003cfilesystem::path\u003e rglob(string pathname);\n```\n\nThere are also two convenience functions to `glob` on a list of patterns:\n\n```cpp\n/// e.g., glob({\"*.png\", \"*.jpg\"})\nvector\u003cfilesystem::path\u003e glob(vector\u003cstring\u003e pathnames);\n\n/// Globs recursively\n/// e.g., rglob({\"**/*.h\", \"**/*.hpp\", \"**/*.cpp\"})\nvector\u003cfilesystem::path\u003e rglob(vector\u003cstring\u003e pathnames);\n```\n\n## Wildcards\n\n| Wildcard | Matches | Example\n|--- |--- |--- |\n| `*` | any characters | `*.txt` matches all files with the txt extension |\n| `?` | any one character | `???` matches files with 3 characters long |\n| `[]` | any character listed in the brackets | `[ABC]*` matches files starting with A,B or C | \n| `[-]` | any character in the range listed in brackets | `[A-Z]*` matches files starting with capital letters |\n| `[!]` | any character not listed in the brackets | `[!ABC]*` matches files that do not start with A,B or C |\n\n## Examples\n\nThe following examples use the [standalone](standalone/source/main.cpp) sample that is part of this repository to illustrate the library functionality.\n\n```console\nfoo@bar:~$ ./build/standalone/glob -h\nRun glob to find all the pathnames matching a specified pattern\nUsage:\n  ./build/standalone/glob [OPTION...]\n\n  -h, --help       Show help\n  -v, --version    Print the current version number\n  -r, --recursive  Run glob recursively\n  -i, --input arg  Patterns to match\n```\n\n### Match file extensions\n\n```console\nfoo@bar:~$ tree\n.\n├── include\n│   └── foo\n│       ├── bar.hpp\n│       ├── baz.hpp\n│       └── foo.hpp\n└── test\n    ├── bar.cpp\n    ├── doctest.hpp\n    ├── foo.cpp\n    └── main.cpp\n\n3 directories, 7 files\n\nfoo@bar:~$ ./glob -i \"**/*.hpp\"\n\"test/doctest.hpp\"\n\nfoo@bar:~$ ./glob -i \"**/**/*.hpp\"\n\"include/foo/baz.hpp\"\n\"include/foo/foo.hpp\"\n\"include/foo/bar.hpp\"\n```\n\n***NOTE*** If you run glob recursively, i.e., using `rglob`:\n\n```console\nfoo@bar:~$ ./glob -r -i \"**/*.hpp\"\n\"test/doctest.hpp\"\n\"include/foo/baz.hpp\"\n\"include/foo/foo.hpp\"\n\"include/foo/bar.hpp\"\n```\n\n### Match files in absolute pathnames\n\n```console\nfoo@bar:~$ ./glob -i '/usr/local/include/nc*.h'\n\"/usr/local/include/ncCheck.h\"\n\"/usr/local/include/ncGroupAtt.h\"\n\"/usr/local/include/ncUshort.h\"\n\"/usr/local/include/ncByte.h\"\n\"/usr/local/include/ncString.h\"\n\"/usr/local/include/ncUint64.h\"\n\"/usr/local/include/ncGroup.h\"\n\"/usr/local/include/ncUbyte.h\"\n\"/usr/local/include/ncvalues.h\"\n\"/usr/local/include/ncInt.h\"\n\"/usr/local/include/ncAtt.h\"\n\"/usr/local/include/ncVar.h\"\n\"/usr/local/include/ncUint.h\"\n```\n\n### Wildcards: Match a range of characters listed in brackets ('[]')\n\n```console\nfoo@bar:~$ ls test_files_02\n1.txt 2.txt 3.txt 4.txt\n\nfoo@bar:~$ ./glob -i 'test_files_02/[0-9].txt'\n\"test_files_02/4.txt\"\n\"test_files_02/3.txt\"\n\"test_files_02/2.txt\"\n\"test_files_02/1.txt\"\n\nfoo@bar:~$ ./glob -i 'test_files_02/[1-2]*'\n\"test_files_02/2.txt\"\n\"test_files_02/1.txt\"\n```\n\n```console\nfoo@bar:~$ ls test_files_03\nfile1.txt file2.txt file3.txt file4.txt\n\nfoo@bar:~$ ./glob -i 'test_files_03/file[0-9].*'\n\"test_files_03/file2.txt\"\n\"test_files_03/file3.txt\"\n\"test_files_03/file1.txt\"\n\"test_files_03/file4.txt\"\n```\n\n### Exclude files from the matching\n\n```console\nfoo@bar:~$ ls test_files_01\n__init__.py     bar.py      foo.py\n\nfoo@bar:~$ ./glob -i 'test_files_01/*[!__init__].py'\n\"test_files_01/bar.py\"\n\"test_files_01/foo.py\"\n\nfoo@bar:~$ ./glob -i 'test_files_01/*[!__init__][!bar].py'\n\"test_files_01/foo.py\"\n\nfoo@bar:~$ ./glob -i 'test_files_01/[!_]*.py'\n\"test_files_01/bar.py\"\n\"test_files_01/foo.py\"\n```\n\n### Wildcards: Match any one character with question mark ('?')\n\n```console\nfoo@bar:~$ ls test_files_02\n1.txt 2.txt 3.txt 4.txt\n\nfoo@bar:~$ ./glob -i 'test_files_02/?.txt'\n\"test_files_02/4.txt\"\n\"test_files_02/3.txt\"\n\"test_files_02/2.txt\"\n\"test_files_02/1.txt\"\n```\n\n```console\nfoo@bar:~$ ls test_files_03\nfile1.txt file2.txt file3.txt file4.txt\n\nfoo@bar:~$ ./glob -i 'test_files_03/????[3-4].txt'\n\"test_files_03/file3.txt\"\n\"test_files_03/file4.txt\"\n```\n\n### Case sensitivity\n\n`glob` matching is case-sensitive:\n\n```console\nfoo@bar:~$ ls test_files_05\nfile1.png file2.png file3.PNG file4.PNG\n\nfoo@bar:~$ ./glob -i 'test_files_05/*.png'\n\"test_files_05/file2.png\"\n\"test_files_05/file1.png\"\n\nfoo@bar:~$ ./glob -i 'test_files_05/*.PNG'\n\"test_files_05/file3.PNG\"\n\"test_files_05/file4.PNG\"\n\nfoo@bar:~$ ./glob -i \"test_files_05/*.png\",\"test_files_05/*.PNG\"\n\"test_files_05/file2.png\"\n\"test_files_05/file1.png\"\n\"test_files_05/file3.PNG\"\n\"test_files_05/file4.PNG\"\n```\n\n### Tilde expansion\n\n```console\nfoo@bar:~$ ./glob -i \"~/.b*\"\n\"/Users/pranav/.bashrc\"\n\"/Users/pranav/.bash_sessions\"\n\"/Users/pranav/.bash_profile\"\n\"/Users/pranav/.bash_history\"\n\nfoo@bar:~$ ./glob -i \"~/Documents/Projects/glob/**/glob/*.h\"\n\"/Users/pranav/Documents/Projects/glob/include/glob/glob.h\"\n```\n\n## Contributing\nContributions are welcome, have a look at the [CONTRIBUTING.md](CONTRIBUTING.md) document for more information.\n\n## License\nThe project is available under the [MIT](https://opensource.org/licenses/MIT) license.\n","funding_links":[],"categories":["File Managment","C++","File System"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-ranav%2Fglob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp-ranav%2Fglob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-ranav%2Fglob/lists"}