-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirectory.cc
More file actions
49 lines (42 loc) · 947 Bytes
/
directory.cc
File metadata and controls
49 lines (42 loc) · 947 Bytes
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
/*
* InvertedIndex - Search words inside .txt files in a dir
* Copyright (C) 2015 Gianfranco Mariotti
*/
#include <dirent.h>
#include <string>
#include <list>
#include "directory.h"
#include "utils.h"
void Directory::GetDirFiles(const std::string& dir_str,const std::string& ext)
{
DIR *dir;
struct dirent *ent;
if ((dir = opendir (dir_str.c_str())) != NULL)
{
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL)
{
if(utils::has_suffix((ent->d_name),ext))
files_list.push_back(Document(dir_str,ent->d_name));
}
closedir (dir);
error = false;
}
else
{
/* could not open directory */
error = true;
error_code = "Dir Cannot Be Opened";
}
}
Directory::Directory(std::string dir_str_, std::string ext_)
{
dir_str = dir_str_;
ext = ext_;
GetDirFiles(dir_str,ext);
if( files_list.empty() && error==false )
{
error = true;
error_code = "No Files";
}
}