All Projects → p-ranav → Glob

p-ranav / Glob

Licence: mit
Glob for C++17

Programming Languages

cpp11
221 projects
cpp17
186 projects
cpp14
131 projects

Projects that are alternatives of or similar to Glob

Tiny Glob
Super tiny and ~350% faster alternative to node-glob
Stars: ✭ 710 (+859.46%)
Mutual labels:  pattern-matching, filesystem, glob
lfs
Lightweight file system
Stars: ✭ 12 (-83.78%)
Mutual labels:  lightweight, filesystem
glob
Pure Nim library for matching file paths against Unix style glob patterns.
Stars: ✭ 58 (-21.62%)
Mutual labels:  filesystem, glob
jobflow
runs stuff in parallel (like GNU parallel, but much faster and memory-efficient)
Stars: ✭ 67 (-9.46%)
Mutual labels:  lightweight, unix
Aaru
Aaru Data Preservation Suite
Stars: ✭ 193 (+160.81%)
Mutual labels:  unix, filesystem
Nanomatch
Fast, minimal glob matcher for node.js. Similar to micromatch, minimatch and multimatch, but without support for extended globs (extglobs), posix brackets or braces, and with complete Bash 4.3 wildcard support: ("*", "**", and "?").
Stars: ✭ 79 (+6.76%)
Mutual labels:  pattern-matching, glob
whichpm
Locates installed Perl modules.
Stars: ✭ 20 (-72.97%)
Mutual labels:  unix, filesystem
Draxt
draxt.js – NodeList/jQuery-like package for File System (node.js)
Stars: ✭ 192 (+159.46%)
Mutual labels:  filesystem, glob
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-71.62%)
Mutual labels:  filesystem, glob
Bfs
A breadth-first version of the UNIX find command
Stars: ✭ 336 (+354.05%)
Mutual labels:  unix, filesystem
Rm Protection
A safe alternative for "rm".
Stars: ✭ 416 (+462.16%)
Mutual labels:  unix, filesystem
Fast Glob
🚀 It's a very fast and efficient glob library for Node.js
Stars: ✭ 1,150 (+1454.05%)
Mutual labels:  filesystem, glob
Lfs
A thing to get information on your mounted disks
Stars: ✭ 178 (+140.54%)
Mutual labels:  unix, filesystem
Advanced-xv6
Modern improvements for MIT's xv6 OS
Stars: ✭ 26 (-64.86%)
Mutual labels:  unix, filesystem
Copy Webpack Plugin
Copy files and directories with webpack
Stars: ✭ 2,679 (+3520.27%)
Mutual labels:  filesystem, glob
ModernOperatingSystems AndrewTanenbaum
My notes after reading 'Modern Operating Systems' book by Andrew Tanenbaum and Herbert Bos.
Stars: ✭ 71 (-4.05%)
Mutual labels:  unix, filesystem
Xcv
✂️ Cut, Copy and Paste files with Bash
Stars: ✭ 144 (+94.59%)
Mutual labels:  filesystem, glob
findlargedir
find all "blackhole" directories with a huge amount of filesystem entries in a flat structure
Stars: ✭ 15 (-79.73%)
Mutual labels:  unix, filesystem
Buildxl
Microsoft Build Accelerator
Stars: ✭ 676 (+813.51%)
Mutual labels:  unix, filesystem
Fdir
⚡ The fastest directory crawler & globbing library for NodeJS. Crawls 1m files in < 1s
Stars: ✭ 777 (+950%)
Mutual labels:  filesystem, glob

Unix-style pathname pattern expansion

Table of Contents

Quick Start

  • This library is available in two flavors:
    1. Two file version: glob.h and glob.cpp
    2. Single header file version in single_include/
  • No external dependencies - just the standard library
  • Requires C++17 std::filesystem
  • MIT License

Build Library and Standalone Sample

cmake -Hall -Bbuild
cmake --build build

# run standalone `glob` sample
./build/standalone/glob --help

Usage

// Match on a single pattern
for (auto& p : glob::glob("~/.b*")) {                // e.g., .bash_history, .bashrc
  // do something with `p`
}

// Match on multiple patterns
for (auto& p : glob::glob({"*.png", "*.jpg"})) {     // e.g., foo.png, bar.jpg
  // do something with `p`
}

// Match recursively with `rglob`
for (auto& p : glob::rglob("**/*.hpp")) {            // e.g., include/foo.hpp, include/foo/bar.hpp
  // do something with `p`
}

API

/// e.g., glob("*.hpp")
/// e.g., glob("**/*.cpp")
/// e.g., glob("test_files_02/[0-9].txt")
/// e.g., glob("/usr/local/include/nc*.h")
/// e.g., glob("test_files_02/?.txt")
vector<filesystem::path> glob(string pathname);

/// Globs recursively
/// e.g., rglob("Documents/Projects/Foo/**/*.hpp")
/// e.g., rglob("test_files_02/*[0-9].txt")
vector<filesystem::path> rglob(string pathname);

There are also two convenience functions to glob on a list of patterns:

/// e.g., glob({"*.png", "*.jpg"})
vector<filesystem::path> glob(vector<string> pathnames);

/// Globs recursively
/// e.g., rglob({"**/*.h", "**/*.hpp", "**/*.cpp"})
vector<filesystem::path> rglob(vector<string> pathnames);

Wildcards

Wildcard Matches Example
* any characters *.txt matches all files with the txt extension
? any one character ??? matches files with 3 characters long
[] any character listed in the brackets [ABC]* matches files starting with A,B or C
[-] any character in the range listed in brackets [A-Z]* matches files starting with capital letters
[!] any character listed in the brackets [!ABC]* matches files that do not start with A,B or C

Examples

The following examples use the standalone sample that is part of this repository to illustrate the library functionality.

[email protected]:~$ ./build/standalone/glob -h
Run glob to find all the pathnames matching a specified pattern
Usage:
  ./build/standalone/glob [OPTION...]

  -h, --help       Show help
  -v, --version    Print the current version number
  -r, --recursive  Run glob recursively
  -i, --input arg  Patterns to match

Match file extensions

[email protected]:~$ tree
.
├── include
│   └── foo
│       ├── bar.hpp
│       ├── baz.hpp
│       └── foo.hpp
└── test
    ├── bar.cpp
    ├── doctest.hpp
    ├── foo.cpp
    └── main.cpp

3 directories, 7 files

[email protected]:~$ ./glob -i "**/*.hpp"
"test/doctest.hpp"

[email protected]:~$ ./glob -i "**/**/*.hpp"
"include/foo/baz.hpp"
"include/foo/foo.hpp"
"include/foo/bar.hpp"

NOTE If you run glob recursively, i.e., using rglob:

[email protected]:~$ ./glob -r -i "**/*.hpp"
"test/doctest.hpp"
"include/foo/baz.hpp"
"include/foo/foo.hpp"
"include/foo/bar.hpp"

Match files in absolute pathnames

[email protected]:~$ ./glob -i '/usr/local/include/nc*.h'
"/usr/local/include/ncCheck.h"
"/usr/local/include/ncGroupAtt.h"
"/usr/local/include/ncUshort.h"
"/usr/local/include/ncByte.h"
"/usr/local/include/ncString.h"
"/usr/local/include/ncUint64.h"
"/usr/local/include/ncGroup.h"
"/usr/local/include/ncUbyte.h"
"/usr/local/include/ncvalues.h"
"/usr/local/include/ncInt.h"
"/usr/local/include/ncAtt.h"
"/usr/local/include/ncVar.h"
"/usr/local/include/ncUint.h"

Wildcards: Match a range of characters listed in brackets ('[]')

[email protected]:~$ ls test_files_02
1.txt 2.txt 3.txt 4.txt

[email protected]:~$ ./glob -i 'test_files_02/[0-9].txt'
"test_files_02/4.txt"
"test_files_02/3.txt"
"test_files_02/2.txt"
"test_files_02/1.txt"

[email protected]:~$ ./glob -i 'test_files_02/[1-2]*'
"test_files_02/2.txt"
"test_files_02/1.txt"
[email protected]:~$ ls test_files_03
file1.txt file2.txt file3.txt file4.txt

[email protected]:~$ ./glob -i 'test_files_03/file[0-9].*'
"test_files_03/file2.txt"
"test_files_03/file3.txt"
"test_files_03/file1.txt"
"test_files_03/file4.txt"

Exclude files from the matching

[email protected]:~$ ls test_files_01
__init__.py     bar.py      foo.py

[email protected]:~$ ./glob -i 'test_files_01/*[!__init__].py'
"test_files_01/bar.py"
"test_files_01/foo.py"

[email protected]:~$ ./glob -i 'test_files_01/*[!__init__][!bar].py'
"test_files_01/foo.py"

[email protected]:~$ ./glob -i 'test_files_01/[!_]*.py'
"test_files_01/bar.py"
"test_files_01/foo.py"

Wildcards: Match any one character with question mark ('?')

[email protected]:~$ ls test_files_02
1.txt 2.txt 3.txt 4.txt

[email protected]:~$ ./glob -i 'test_files_02/?.txt'
"test_files_02/4.txt"
"test_files_02/3.txt"
"test_files_02/2.txt"
"test_files_02/1.txt"
[email protected]:~$ ls test_files_03
file1.txt file2.txt file3.txt file4.txt

[email protected]:~$ ./glob -i 'test_files_03/????[3-4].txt'
"test_files_03/file3.txt"
"test_files_03/file4.txt"

Case sensitivity

glob matching is case-sensitive:

[email protected]:~$ ls test_files_05
file1.png file2.png file3.PNG file4.PNG

[email protected]:~$ ./glob -i 'test_files_05/*.png'
"test_files_05/file2.png"
"test_files_05/file1.png"

[email protected]:~$ ./glob -i 'test_files_05/*.PNG'
"test_files_05/file3.PNG"
"test_files_05/file4.PNG"

[email protected]:~$ ./glob -i "test_files_05/*.png","test_files_05/*.PNG"
"test_files_05/file2.png"
"test_files_05/file1.png"
"test_files_05/file3.PNG"
"test_files_05/file4.PNG"

Tilde expansion

[email protected]:~$ ./glob -i "~/.b*"
"/Users/pranav/.bashrc"
"/Users/pranav/.bash_sessions"
"/Users/pranav/.bash_profile"
"/Users/pranav/.bash_history"

[email protected]:~$ ./glob -i "~/Documents/Projects/glob/**/glob/*.h"
"/Users/pranav/Documents/Projects/glob/include/glob/glob.h"

Contributing

Contributions are welcome, have a look at the CONTRIBUTING.md document for more information.

License

The project is available under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].