-
Notifications
You must be signed in to change notification settings - Fork 1
/
ls.cpp
executable file
·64 lines (55 loc) · 1.61 KB
/
ls.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
#include "command.h"
#include <QDebug>
#include <QDir>
#include <QFileInfoList>
#include <QCommandLineParser>
#include "globals.h"
#include <QStringList>
#include <QCommandLineOption>
#include <QFileInfo>
ls::ls(QString input){
cmd = input;
file_list.setNameFilters(QStringList() << "*.txt");
if(cmd.contains(" -at") or cmd.contains(" -ta")){
this->ls_at();
}
else if(cmd.contains(" -a"))
{
this->ls_a();
}
else if(cmd.contains(" -t")){
this->ls_t();
}
else if(cmd.contains(" -h") or cmd.contains("--help") or cmd.contains("-?")){
this->ls_h();
}
else
this->ls_n();
}
void ls::ls_t(){
names = file_list.entryList(QDir::Files|QDir::NoDotAndDotDot|QDir::AllDirs, QDir::Time);
list = names.join(" \n");
out << list <<endl;
}
void ls::ls_a(){
names = file_list.entryList(QDir::Files|QDir::Hidden|QDir::AllDirs);
list = names.join(" \n");
out << list << endl;
}
void ls::ls_h(){
parse.addHelpOption();
parse.setApplicationDescription("\nLists all files in the current directory.\nUse -a opton to lists all files including hidden\n");
out<< parse.helpText() <<endl ;
}
void ls::ls_n(){
foreach (QFileInfo select, file_list.entryList(QDir::Files|QDir::NoDotAndDotDot|QDir::AllDirs)) {
QString list = select.fileName();
out << list << " \n";
}
out << output <<endl;
}
void ls::ls_at(){
names = file_list.entryList(QDir::Files|QDir::Hidden|QDir::AllDirs, QDir::Time );
list = names.join(" \n");
out << list <<endl;
}