Merge pull request #48 from antopilo/NK-141-rename-file&folder
NK-141 - Rename File/Folder
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "FileSystem.h"
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -11,6 +12,8 @@ namespace Nuake
|
||||
static std::string GetFromClipboard();
|
||||
static int GetTime();
|
||||
static void OpenIn(const std::string& filePath);
|
||||
static int OS::RenameFile(const Ref<File>& file, const std::string& newName);
|
||||
static int OS::RenameDirectory(const Ref<Directory>& dir, const std::string& newName);
|
||||
static void ShowInFileExplorer(const std::string& filePath);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user