NK-141 - Rename File & Folder

This commit is contained in:
emerycp
2023-07-22 23:50:29 -04:00
parent a71689a885
commit 2cd11aca04
5 changed files with 131 additions and 13 deletions

View File

@@ -7,6 +7,7 @@
#include <Windows.h>
#include <chrono>
#include <imgui/imgui.h>
using namespace Nuake;
@@ -44,6 +45,25 @@ void OS::OpenIn(const std::string& filePath)
ShellExecuteA(nullptr, "open", filePath.c_str(), nullptr, nullptr, SW_SHOWDEFAULT);
}
int OS::RenameFile(const Ref<File>& file, const std::string& newName)
{
std::string extension = !String::EndsWith(newName, file->GetExtension().c_str()) ? file->GetExtension() : "";
std::string newFilePath = file->GetParent()->fullPath + newName + extension;
std::error_code resultError;
std::filesystem::rename(file->GetAbsolutePath().c_str(), newFilePath.c_str(), resultError);
return resultError.value() == 0;
}
int OS::RenameDirectory(const Ref<Directory>& dir, const std::string& newName)
{
std::string newDirPath = dir->Parent->fullPath + newName;
std::error_code resultError;
std::filesystem::rename(dir->fullPath.c_str(), newDirPath.c_str(), resultError);
return resultError.value() == 0;
}
void OS::ShowInFileExplorer(const std::string& filePath)
{
ShellExecuteA(nullptr, "open", "explorer.exe", ("/select," + std::string(filePath)).c_str(), nullptr, SW_SHOWDEFAULT);