https://github.com/artemvlas/pathstr
Handling file system paths as strings
https://github.com/artemvlas/pathstr
filesystem library path qt string
Last synced: about 2 months ago
JSON representation
Handling file system paths as strings
- Host: GitHub
- URL: https://github.com/artemvlas/pathstr
- Owner: artemvlas
- License: mit
- Created: 2025-05-04T19:35:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-07-19T19:36:25.000Z (12 months ago)
- Last Synced: 2025-07-19T22:31:31.207Z (12 months ago)
- Topics: filesystem, library, path, qt, string
- Language: C++
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pathstr
### _A small library for handling filesystem paths as strings (Qt)._
The library performs generic operations with the file system paths, processing them as strings.
More suitable for handling a large number of strings/paths than stock functions do (QFile/QFileInfo/QDir).\
In some cases, it performs common operations much faster, and also has more convenient handling of common exceptions.
#### For example:
* Concatenate path strings, checking for absence of separator duplication.
* Get the folder name or the parent folder path regardless of the separator at the end of the path.
### The project purpose:
Creation of a minimalist tool with a focus on increased performance and predictability.
### Key features:
* Joining paths. Automatic check of the separator presence.
* Getting relative path.
* Changing the file extension.
* Changing the file name, keeping the path and suffix unchanged.
* Obtaining a parent folder. Even if the path ends with a slash.
* Checking a match of the file extension with the listed ones.
* Obtaining the name of the file system entry, excluding the path.
### Usage
Integration as a submodule can be used:
```
git submodule add https://github.com/artemvlas/pathstr
```
and add to the main project's _CMakeLists.txt_ file:
```
add_subdirectory(pathstr)
```
Then in the code:
```
#include "pathstr.h"
using namespace pathstr;
QString fooName = entryName("/home/fooFolder/"); // -> "fooFolder"
QString newSuffix = setSuffix("file.txt", "zip"); // -> "file.zip"
QString newFile = renameFile("folder/file.docx", "newFile"); // -> folder/newFile.docx
QString fullPath = joinPath("/absolutePath", "addPath"); // -> "/absolutePath/addPath"
QString relPath = relativePath("/rootFolder", "/rootFolder/folder2/file"); // -> "folder2/file"
bool has_suffix = hasExtension("file.txt", {"jpg", "txt", "json"}); // -> true
```