-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRenameMode.cpp
65 lines (44 loc) · 1.88 KB
/
RenameMode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <filesystem>
#include <vector>
#include "RenameMode.h"
#include "Utils.h"
RenameMode::RenameMode(const std::string& filter, const std::string& folder, const std::string& prefix, int startNumber)
: Mode{ filter, folder }
, m_Prefix{ prefix }
, m_startNumber{ startNumber }
{}
const std::string& RenameMode::GetModeName() const
{
static const std::string RenameModeName = "[Renomear]: ";
return RenameModeName;
}
void RenameMode::RunImpl()
{
std::cout << GetModeName() << "Modo : Renomear" << std::endl;
std::cout << GetModeName() << "Pasta : " << GetFolder() << std::endl;
std::cout << GetModeName() << "Filtro : " << GetFilter() << std::endl;
std::cout << GetModeName() << "Prefixo : " << m_Prefix << std::endl;
std::cout << GetModeName() << "Número Inicial : " << m_startNumber << std::endl;
// Iniciar o processo de renomear os arquivos
// "Absolute Zero.jpg" -> "PrefixN,jpg"
int currentNumber = m_startNumber;
for(const std::filesystem::path& filepath : GetFiles())
{
const std::filesystem::path extension = filepath.extension();
const std::string newFileName = m_Prefix + std::to_string(currentNumber) + extension.string();
std::filesystem::path newFilepath = filepath;
newFilepath.replace_filename(newFileName);
try
{
std::filesystem::rename(filepath, newFilepath);
std::cout << GetModeName() << filepath << " -> " << newFilepath << std::endl;
}
catch(const std::exception& exception)
{
std::cerr << GetModeName() << "Erro ao renomear " << filepath << ": " << exception.what() << std::endl;
}
// std::cout << GetModeName() << filepath << " -> " << newFilepath << std::endl;
currentNumber++;
}
}