-
Notifications
You must be signed in to change notification settings - Fork 0
/
mva.cpp
50 lines (40 loc) · 1022 Bytes
/
mva.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
#include <iostream>
#include <string.h>
#include <filesystem>
namespace fs = std::filesystem;
using namespace std;
string replaceString(string s, string what, string with)
{
int index;
while ((index = s.find(what)) != string::npos)
s.replace(index, what.length(), with);
return s;
}
int main(int argc, char** argv)
{
if (argc != 3)
{
printf("usage: mva src-dir dst-dir");
return 1;
}
string _to = string(argv[2]) + "/";
_to = replaceString(_to, "//", "/");
for (auto& p : fs::directory_iterator(argv[1]))
{
try
{
if (fs::is_directory(p))
continue;
auto path = p.path();
auto name = path.filename();
auto to_name = _to + name.string();
fs::rename(path, to_name);
cout << path << " -> \"" << to_name << "\"" << endl;
}
catch (const std::exception& e)
{
cerr << e.what() << endl;
}
}
return 0;
}