-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
87 lines (59 loc) · 2.08 KB
/
main.cpp
File metadata and controls
87 lines (59 loc) · 2.08 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <exception>
#include <iostream>
#include <QSet>
#include <QVector>
#include <QTextCodec>
#include <QTextStream>
#include <QDirIterator>
#include <QCoreApplication>
#include <QFileSystemWatcher>
#include <qdebug.h>
QVector<QString> IterateAndDisplayContent(QString path) {
QVector<QString> entries;
QDirIterator folderIt(path, {}, QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
qDebug() << Qt::endl << " ----------------------------------[ Folder Contents ]----------------------------- " << Qt::endl << Qt::endl;
int position = 0;
while (folderIt.hasNext()) {
QFile file(folderIt.next());
entries.insert(position, file.fileName());
qDebug() << position << " " << file.fileName() << Qt::endl;
position++;
}
position = 1;
return entries;
}
int main(int argc, char* argv[]) {
try {
QCoreApplication a(argc, argv);
QVector<QString> entriesNew, entriesOld;
QTextStream input(stdin);
input.setCodec("UTF-8");
input.autoDetectUnicode();
QTextStream output(stdout);
output.setCodec("UTF-8");
output.autoDetectUnicode();
// --- Read User Input & Test Message
QString path;
output << "Enter Valid File Path : " << Qt::endl;
path = input.readLine();
// ---- Pass the path and start watching the directory
do{
QFileSystemWatcher* watcher = new QFileSystemWatcher();
if (!watcher->files().contains(path))
{
watcher->addPath(path);
output << " Directory added " << Qt::endl;
}
QStringList directoryList = watcher->directories();
Q_FOREACH(QString directory, directoryList)
qDebug() << "Directory name" << directory << "\n";
// ---- Iterate throught folder Contents
entriesOld = IterateAndDisplayContent(path);
} while (true);
return a.exec();
}
catch (const std::exception& ex)
{
std::cout << ex.what();
}
}