zhangxiangxiao / cppglob

C++ port of Python glob module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C++ GLOB library

made-with-cpp Build Status Build status Codacy Badge Report codecov GitHub license PRs Welcome GitHub last commit

cppglob is a C++ port of Python glob module.

Currently cppglob supports the following functions.

  • glob(pattern, recursive = false)
  • iglob(pattern, recursive = false)
  • escape(pathname)

⚠️ This project is no longer maintained. If anyone is interested in continuing the project, let me know so that I can transfer ownership of this repository.

Prerequisites

  • OS: Windows, OSX, Linux
  • Compiler: Currently the following compilers are supported.
    • MSVC >= 19.14 (Visual Studio 2017 version 15.7.1)
    • GCC >= 8.1
    • Clang >= 3.5.0 (with libstdc++), >= 7.0.0 (with libc++)
  • Cmake >= 3.1.0

Install

Using CMake

$ mkdir -p build
$ cd build
$ cmake -DBUILD_SHARED_LIBS=ON ..
$ make
$ sudo make install

Integrate with VC++ project

Currently you must place all header files and sources into the proper directories.

  • headers: include/*/*.hpp
  • sources: src/*.cpp

I'm developing the Nuget package.

If the package released, you can easily integrate this project using GUI plugin.

Example

#include <vector>
#include <list>
#include <algorithm>
#include <filesystem>
#include <cppglob/glob.hpp>  // cppglob::glob
#include <cppglob/iglob.hpp>  // cppglob::iglob

namespace fs = std::filesystem;

int main() {
    // get all files and directories in the same directory
    std::vector<fs::path> entries = cppglob::glob("./*");
    
    // get all directories in the directory dir_a/
    std::vector<fs::path> dirs = cppglob::glob("dir_a/*/");
    
    // get all text files under the directory dir_b/ (recursively searched)
    std::vector<fs::path> files = cppglob::glob("dir_b/**/*.txt", true);

    // get all pdf files in docs/ directory in order of file name.
    std::vector<fs::path> pdf_files = cppglob::glob("docs/*.pdf");
    std::sort(pdf_files.begin(), pdf_files.end());

    // get all pdf files in docs/ directory in order of file name. (with iglob)
    cppglob::glob_iterator it = cppglob::iglob("docs/*.pdf"), end;
    std::list<fs::path> pdf_file_list(it, end);
    pdf_file_list.sort();
}

TODO

  • Conan package
  • Nuget package
  • C++14 support (with <experimental/filesystem> or <boost/filesystem>)
  • support CPPGLOB_HEADER_ONLY macro
  • Performance improvement

About

C++ port of Python glob module

License:MIT License


Languages

Language:C++ 60.2%Language:CMake 39.8%