{"id":15047963,"url":"https://github.com/tdegeus/cpppath","last_synced_at":"2025-07-05T02:35:41.580Z","repository":{"id":40755707,"uuid":"130963402","full_name":"tdegeus/cpppath","owner":"tdegeus","description":"Simple file-path module for C++","archived":false,"fork":false,"pushed_at":"2022-06-24T15:26:08.000Z","size":46,"stargazers_count":10,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T01:12:04.966Z","etag":null,"topics":["cpp","path"],"latest_commit_sha":null,"homepage":null,"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/tdegeus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-25T06:53:10.000Z","updated_at":"2024-12-18T21:57:12.000Z","dependencies_parsed_at":"2022-07-29T08:49:19.239Z","dependency_job_id":null,"html_url":"https://github.com/tdegeus/cpppath","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/tdegeus/cpppath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdegeus%2Fcpppath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdegeus%2Fcpppath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdegeus%2Fcpppath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdegeus%2Fcpppath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tdegeus","download_url":"https://codeload.github.com/tdegeus/cpppath/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tdegeus%2Fcpppath/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263671838,"owners_count":23494047,"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":["cpp","path"],"created_at":"2024-09-24T21:06:20.516Z","updated_at":"2025-07-05T02:35:41.562Z","avatar_url":"https://github.com/tdegeus.png","language":"C++","readme":"# cpppath\n\n[![CI](https://github.com/tdegeus/cpppath/workflows/CI/badge.svg)](https://github.com/tdegeus/cpppath/actions)\n[![Conda Version](https://img.shields.io/conda/vn/conda-forge/cpppath.svg)](https://anaconda.org/conda-forge/cpppath)\n\nSimple, header only, file-path module for C++ similar to `os` in Python. This module is nothing fancy, but it might be helpful to accomplish some simple tasks.\n\n## Contents\n\n\u003c!-- MarkdownTOC --\u003e\n\n- [Disclaimer](#disclaimer)\n- [Getting cpppath](#getting-cpppath)\n    - [Using conda](#using-conda)\n    - [From source](#from-source)\n- [Usage](#usage)\n- [Compiling](#compiling)\n    - [Using CMake](#using-cmake)\n    - [Using pkg-config](#using-pkg-config)\n    - [By hand](#by-hand)\n- [Overview](#overview)\n    - [cpppath::sep](#cpppathsep)\n    - [cpppath::dirname](#cpppathdirname)\n    - [cpppath::filename](#cpppathfilename)\n    - [cpppath::filebase](#cpppathfilebase)\n    - [cpppath::splitext](#cpppathsplitext)\n    - [cpppath::ext](#cpppathext)\n    - [cpppath::split](#cpppathsplit)\n    - [cpppath::join](#cpppathjoin)\n    - [cpppath::select](#cpppathselect)\n    - [cpppath::normpath](#cpppathnormpath)\n    - [cpppath::commonprefix](#cpppathcommonprefix)\n    - [cpppath::commondirname](#cpppathcommondirname)\n    - [cpppath::exists](#cpppathexists)\n    - [cpppath::curdir](#cpppathcurdir)\n\n\u003c!-- /MarkdownTOC --\u003e\n\n# Disclaimer\n\nThis library is free to use under the [MIT license](https://github.com/tdegeus/cpppath/blob/master/LICENSE). Any additions are very much appreciated, in terms of suggested functionality, code, documentation, testimonials, word-of-mouth advertisement, etc. Bug reports or feature requests can be filed on [GitHub](https://github.com/tdegeus/cpppath). As always, the code comes with no guarantee. None of the developers can be held responsible for possible mistakes.\n\nDownload: [.zip file](https://github.com/tdegeus/cpppath/zipball/master) | [.tar.gz file](https://github.com/tdegeus/cpppath/tarball/master).\n\n(c - [MIT](https://github.com/tdegeus/cpppath/blob/master/LICENSE)) T.W.J. de Geus (Tom) | tom@geus.me | www.geus.me | [github.com/tdegeus/cpppath](https://github.com/tdegeus/cpppath)\n\n# Getting cpppath\n\n## Using conda\n\n```bash\nconda install -c conda-forge cpppath\n```\n\n## From source\n\n```bash\n# Download cpppath\ngit checkout https://github.com/tdegeus/cpppath.git\ncd cpppath\n\n# For CMake or pkg-config use\ncmake .\nmake install\n```\n\n# Usage\n\nThis library is header only, so one just has to\n\n```cpp\n#include \u003ccpppath.h\u003e\n```\n\nand make sure that the header is in the include path of the compiler. See below.\n\nConsider this micro-example:\n\n```cpp\n#include \u003ccpppath.h\u003e\n\nint main()\n{\n    std::cout \u003c\u003c cpppath::join({\"path\", \"to\", \"foo\", \"bar.txt\"}) \u003c\u003c std::endl;\n    return 0;\n}\n```\n\nwhich will print\n\n* Unix: `\"path/to/foo/bar.txt\"`\n* Windows: `\"path\\to\\foo\\bar.txt\"`\n\n\u003e   All functions take the file-path separator as argument to allow customisation. To overwrite the library-wide default `/` on Unix and `\\` use:\n\u003e\n\u003e   ```cpp\n\u003e   #define CPPPATH_SEP \"/\"\n\u003e   ```\n\u003e\n\u003e   **before** including *cpppath* for the first time.\n\n# Compiling\n\n## Using CMake\n\nThe `CMakeLists.txt` can be as follows\n\n```cmake\ncmake_minimum_required(VERSION 3.1)\nproject(example)\nfind_package(cpppath REQUIRED)\nadd_executable(example example.cpp)\ntarget_link_libraries(example PRIVATE cpppath)\n```\n\nCompilation can then proceed using\n\n*   Unix:\n\n    ```\n    cmake .\n    make\n    ```\n\n*   Windows:\n\n    ```none\n    cmake -G\"NMake Makefiles\" .\n    nmake\n    ```\n\n## Using pkg-config\n\nPresuming that the compiler is `c++`, compile using (Unix):\n\n```\nc++ `pkg-config --cflags cpppath` ...\n```\n\n## By hand\n\nPresuming that the compiler is `c++`, compile using (Unix):\n\n```\nc++ -I/path/to/cpppath/include ...\n```\n\n# Overview\n\n## cpppath::sep\n\nGet OS's separator.\n\n* Unix: `\"/\"`\n* Windows: `\"\\\\\"`\n\n## cpppath::dirname\n\nGet dirname part of a path.\nDepending on the path, an empty string may be returned.\n\nExample:\n\n```cpp\nstd::cout \u003c\u003c cpppath::dirname(\"/path/to/foo/bar.txt\") \u003c\u003c std::endl;\n```\n\noutputs:\n\n```\n\"/path/to/foo\"\n```\n\n## cpppath::filename\n\nGet filename part of a path.\nDepending on the path, an empty string may be returned.\n\nExample:\n\n```cpp\nstd::cout \u003c\u003c cpppath::filename(\"/path/to/foo/bar.txt\") \u003c\u003c std::endl;\n```\n\noutputs:\n\n```\n\"bar.txt\"\n```\n\n## cpppath::filebase\n\nGet filename part of a path, *without extension*.\nDepending on the path, an empty string may be returned.\n\nExample:\n\n```cpp\nstd::cout \u003c\u003c cpppath::filebase(\"/path/to/foo/bar.txt\") \u003c\u003c std::endl;\n```\n\noutputs:\n\n```\n\"bar\"\n```\n\n## cpppath::splitext\n\nSplit the pathname path into a pair `(root, ext)` such that `root + ext == path`,\nand `ext` is empty or begins with a period and contains at most one period.\nLeading periods on the basename are ignored; `cpppath::splitext(\".cshrc\")` returns `{\".cshrc\", \"\"}`.\n\n## cpppath::ext\n\nGet the extension of a path.\nDepending on the path, an empty string may be returned.\n\nExample:\n\n```cpp\nstd::cout \u003c\u003c cpppath::ext(\"/path/to/foo/bar.txt\") \u003c\u003c std::endl;\n```\n\noutputs:\n\n```\n\"txt\"\n```\n\n## cpppath::split\n\nSplit sub-paths using the separator. The output is a list of path components.\n\nOptionally the list can be sliced as `cpppath::split(path, begin, end)` (Python equivalent: `os.split(path)[begin: end]`). Negative indices may be used to that count from the right (instead of from the left).\n\n## cpppath::join\n\nJoin path components using separator.\nProvides option to prepend the output string with the separator.\n\n## cpppath::select\n\nSelection of sub-paths (see `split`). Negative indices may be used to that count from the right (instead of from the left).\n\nExample 1:\n\n```cpp\nstd::cout \u003c\u003c cpppath::select(\"/path/to/foo/bar.txt\", 2) \u003c\u003c std::endl;\n```\n\noutputs\n\n```\n\"foo/bar.txt\"\n```\n\nExample 2:\n\n```cpp\nstd::cout \u003c\u003c select(\"/path/to/foo/bar.txt\", 2, 3) \u003c\u003c std::endl;\n```\n\noutputs\n\n```\n\"foo\"\n```\n\n## cpppath::normpath\n\nNormalize a path by collapsing redundant separators and up-level references so that `A//B`, `A/B/`, `A/./B` and `A/foo/../B` all become `A/B`. This string manipulation may change the meaning of a path that contains symbolic links.\n\n## cpppath::commonprefix\n\nSelect the common part of a list of strings. For example:\n\n```cpp\nstd::vector\u003cstd::string\u003e paths = {\"/path/to/id=000/file.txt\", \"/path/to/id=001/file.txt\"};\nstd::cout \u003c\u003c cpppath::commonprefix(paths) \u003c\u003c std::endl;\n```\n\noutputs\n\n```\n\"/path/to/id=00\"\n```\n\n## cpppath::commondirname\n\nSelect the common path of a list of paths. For example:\n\n```cpp\nstd::vector\u003cstd::string\u003e paths = {\"/path/to/id=000/file.txt\", \"/path/to/id=001/file.txt\"};\nstd::cout \u003c\u003c cpppath::commondirname(paths) \u003c\u003c std::endl;\n```\n\noutputs\n\n```\n\"/path/to\"\n```\n\nThis can also be used to select the part of the paths that in unique to each string. For example:\n\n```cpp\nstd::vector\u003cstd::string\u003e paths = {\"/path/to/id=000/file.txt\", \"/path/to/id=001/file.txt\"};\nstd::cout \u003c\u003c cpppath::split(paths[0], cpppath::commondirname(paths)+\"/\")[0] \u003c\u003c std::endl;\n```\n\noutputs\n\n```\n\"id=000/file.txt\"\n```\n\n## cpppath::exists\n\nReturns `true` is the `path` exists.\n\n## cpppath::curdir\n\nThe current working directory.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdegeus%2Fcpppath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftdegeus%2Fcpppath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftdegeus%2Fcpppath/lists"}