/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/NewPlus/NewShellExtensionContextMenu/helpers_filesystem.h
43 строки
1 KB
Christian Gaarden Gaardmark
New+: Fixed issue with files and folders containing only numbers (#45439)
02 мар 2026, 17:16
Не верифицирован
02 мар 2026, 17:16
7e3f9f0
Код
Авторство
О чём код?
#pragma once #include "helpers_variables.h" namespace newplus::helpers::filesystem { inline bool is_directory(const std::filesystem::path path) { const auto entry = std::filesystem::directory_entry(path); return entry.is_directory(); } inline std::wstring make_valid_filename(const std::wstring& string, const wchar_t replace_with = L' ') { // replace all non-filename-valid chars with replace_with wchar std::wstring valid_filename = string; std::replace_if(valid_filename.begin(), valid_filename.end(), [](wchar_t c) { return c == L'/' || c == L'\\' || c == L':' || c == L'*' || c == L'?' || c == L'"' || c == L'<' || c == L'>' || c == L'|'; }, replace_with); return valid_filename; } inline std::wstring make_unique_path_name(const std::wstring& initial_path) { std::filesystem::path folder_path(initial_path); std::filesystem::path path_based_on(initial_path); int counter = 1; while (std::filesystem::exists(folder_path)) { std::wstring new_filename = path_based_on.stem().wstring() + L" (" + std::to_wstring(counter) + L")"; if (path_based_on.has_extension()) { new_filename += path_based_on.extension().wstring(); } folder_path = path_based_on.parent_path() / new_filename; counter++; } return folder_path.wstring(); } }