Created
January 29, 2016 06:44
-
-
Save kennykerr/d346e15c0f6fc6e1730f to your computer and use it in GitHub Desktop.
Revisions
-
kennykerr created this gist
Jan 29, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ #include <windows.h> #include <pathcch.h> #include <string> #pragma comment(lib, "pathcch") namespace impl { void check(HRESULT const result) { if (result != S_OK) { throw result; } } void path_append(std::wstring & path, wchar_t const * const more, size_t const size) { path.resize(path.size() + 5 + size); // \\?\path\more check(PathCchAppendEx(&path[0], path.size() + 1, more, PATHCCH_ALLOW_LONG_PATHS)); path.resize(wcslen(path.c_str())); } void path_append(std::wstring & path, wchar_t const * const more) { path_append(path, more, wcslen(more)); } void path_append(std::wstring & path, std::wstring const & more) { path_append(path, more.c_str(), more.size()); } void path_combine(std::wstring & path) {} template <typename First, typename ... Rest> void path_combine(std::wstring & path, First const & first, Rest const & ... rest) { path_append(path, first); path_combine(path, rest ...); } } template <typename ... T> std::wstring path_combine(T const & ... paths) { std::wstring path; impl::path_combine(path, paths ...); return path; } int main() { std::wstring path = path_combine(L"C:\\root", L"one", L"two", L"three", L"four"); printf("%ls\n", path.c_str()); }