-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
62 lines (49 loc) · 1.14 KB
/
main.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
#include "stdafx.h"
#include "FileTrackerLinux.h"
namespace
{
FileTrackerLinux::EventHandlerFn handler = [](const std::string& dir, const std::string& name)
{
std::cout << "New file detected in " << dir << ": " << name << std::endl;
std::ifstream file;
const auto path = dir + "/" + name;
file.open(path);
auto lines_count{0};
std::string line;
while (std::getline(file, line))
++lines_count;
file.close();
std::remove(path.c_str());
std::cout << "Number of lines in the file: " << lines_count << std::endl;
};
}
int main(int count, char** args)
{
std::vector<std::string> dirs; //{"./test"};
for (auto i = 1; i < count; ++i)
dirs.emplace_back(args[i]);
if (dirs.empty())
{
std::cout << "No directories to track." << std::endl;
return 0;
}
try
{
auto tracker = FileTrackerLinux::create();
for (const auto& dir : dirs)
{
std::cout << "Attaching: " << dir << std::endl;
tracker.track_directory(dir, handler);
}
while (true)
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
tracker.check();
}
}
catch (std::exception& e)
{
std::cout << "Error: " << e.what() << std::endl;
}
return 0;
}