[New+]When new folder name collides, create copy instead of creating inside existing (#35464)

* Fixed target folder path when source is a folder
This commit is contained in:
Christian Gaarden Gaardmark 2024-10-21 03:51:14 -07:00 committed by GitHub
parent 3a6536ce54
commit 5d2bb16e92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 3 deletions

View File

@ -50,6 +50,12 @@ namespace newplus::utilities
return false; return false;
} }
inline bool is_directory(const std::filesystem::path path)
{
const auto entry = std::filesystem::directory_entry(path);
return entry.is_directory();
}
inline bool wstring_same_when_comparing_ignore_case(std::wstring stringA, std::wstring stringB) inline bool wstring_same_when_comparing_ignore_case(std::wstring stringA, std::wstring stringB)
{ {
transform(stringA.begin(), stringA.end(), stringA.begin(), towupper); transform(stringA.begin(), stringA.end(), stringA.begin(), towupper);

View File

@ -70,9 +70,13 @@ IFACEMETHODIMP shell_context_sub_menu_item::Invoke(_In_opt_ IShellItemArray*, _I
// Determine initial filename // Determine initial filename
std::filesystem::path source_fullpath = template_entry->path; std::filesystem::path source_fullpath = template_entry->path;
std::filesystem::path target_fullpath = std::wstring(target_path_name) std::filesystem::path target_fullpath = std::wstring(target_path_name);
+ L"\\"
+ this->template_entry->get_target_filename(!utilities::get_newplus_setting_hide_starting_digits()); // Only append name to target if source is not a directory
if (!utilities::is_directory(target_fullpath))
{
target_fullpath.append(this->template_entry->get_target_filename(!utilities::get_newplus_setting_hide_starting_digits()));
}
// Copy file and determine final filename // Copy file and determine final filename
std::filesystem::path target_final_fullpath = this->template_entry->copy_object_to(GetActiveWindow(), target_fullpath); std::filesystem::path target_final_fullpath = this->template_entry->copy_object_to(GetActiveWindow(), target_fullpath);