platformdirs 0.1.0
📂 Python's platformdirs module for C++
Loading...
Searching...
No Matches
platformdirs for C++

📂 Python's platformdirs module for C++

auto dirs = platformdirs::platform_dirs(app_name, app_author, "1.0");
std::println("user_data_dir: {}", dirs.user_data_dir());
std::println("user_config_dir: {}", dirs.user_config_dir());
std::println("user_cache_dir: {}", dirs.user_cache_dir());
std::println("user_state_dir: {}", dirs.user_state_dir());
std::println("user_log_dir: {}", dirs.user_log_dir());
std::println("...and more!");
platformdirs::unix::unix platform_dirs
Definition platformdirs.h:231
user_data_dir: ~/.local/share/MyApp/1.0
user_config_dir: ~/.config/MyApp/1.0
user_cache_dir: ~/.cache/MyApp/1.0
user_state_dir: ~/.local/state/MyApp/1.0
user_log_dir: ~/.local/state/MyApp/1.0/log
...and more!

🐍 Same API surface as platformdirs \ 🔺 Works great with CMake \ 💅 Uses platformdirs' opinionated directories \ 🟦 Works on Windows \ 🌌 Works with cosmocc!

Installation

CMake

CMake find_package() with FetchContent fallback

include(FetchContent)
FetchContent_Declare(platformdirs
GIT_REPOSITORY https://github.com/jcbhmr/platformdirs-cpp.git
GIT_TAG v0.1.0
FIND_PACKAGE_ARGS 0.1.0...<1)
# Will try find_package(platformdirs 0.1.0...<1) first
FetchContent_MakeAvailable(platformdirs)
# ...
# Now link it into your app/lib target
target_link_libraries(myapp platformdirs::platformdirs)
target_link_libraries(mylib platformdirs::platformdirs)

Usage

C++

main.cpp
#include <print>
#include <platformdirs.h>
int main() {
std::println("my app config: {}", platformdirs::user_config_dir("myapp", "me", "1.2.3"));
return 0;
}
std::string user_config_dir(const std::optional< std::string > &appname=std::nullopt, const std::variant< std::string, std::nullopt_t, bool > &appauthor=std::nullopt, const std::optional< std::string > &version=std::nullopt, bool roaming=false, bool ensure_exists=false)
Definition platformdirs.cpp:28
int main(int argc, char *argv[])
Definition platformdirs_exe.cpp:6

📚 See the complete API surface on the website

💡 Pro tip: there's an included platformdirs executable which prints a report of all the config dirs for you. It's great for debugging! 😉

Development

CMake

cmake --workflow --preset default
cmake --workflow --preset test