create rename file

This commit is contained in:
chatlanin
2023-04-02 12:01:04 +03:00
parent 84fc7a1976
commit c451d859a7
6 changed files with 110 additions and 1 deletions

View File

@@ -204,6 +204,31 @@ namespace rrr
check_cursor_position();
}
void content::rename_file(std::filesystem::path old_name, std::filesystem::path new_name)
{
if (std::filesystem::exists(new_name))
{
new_name = new_name.filename().string() + "_" +
std::to_string(
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count()
);
new_name = old_name.parent_path() / std::filesystem::path(new_name);
}
hack::utils::unix_cmd("mv " + old_name.string() + " " + new_name.string());
hack::log()(old_name, new_name);
nav.fill(PWD);
tbb::parallel_for(tbb::blocked_range<int>(0, nav.data.size()), [&](tbb::blocked_range<int> r)
{
for (int i = r.begin(); i < r.end(); ++i)
if (nav.data.at(i).path == new_name)
navigation_cursor_position = i;
});
check_cursor_position();
}
void content::delete_file(file f)
{
std::string cmd = "delete " + f.path.string();