-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm.cpp
More file actions
69 lines (63 loc) · 1.56 KB
/
algorithm.cpp
File metadata and controls
69 lines (63 loc) · 1.56 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
#include "algorithm.h"
Algorithm::Algorithm(std::string path) : _path{path}
{
DIR *dp;
struct dirent *dirp;
if((dp= opendir(path.c_str()))==NULL){
//std::cerr<<"No such path";
}
else{
while((dirp= readdir(dp))!=NULL){
std::string current_name = std::string(dirp->d_name);
std::string new_path = path + "/" + current_name;
if(!Algorithm::is_a_folder(new_path)){
number_files.push_back(current_name);
}
else {
number_folder.push_back(current_name);
}
}
}
closedir(dp);
}
int Algorithm::number_of_files(){
return number_files.size();
}
int Algorithm::number_of_folder(){
return number_folder.size();
}
int Algorithm::size_on_disk(){
Algorithm::update_file_size();
return Algorithm::size;
}
/*
std::string Algorithm::breadth_first_search_whole(std::string file_name, std::string path_name){
for(const auto& entry: std::filesystem::recursive_directory_iterator(path_name)){
if(entry.path().filename()==file_name) return entry.path();
}
return "0";
}
*/
std::string Algorithm::file_type(){
if(is_a_folder(_path)) return "Folder";
else return "File";
}
std::string Algorithm::last_modified(){
return Algorithm::date_last_modified;
}
void Algorithm::update_file_size(){
struct stat s;
if(stat(_path.c_str(),&s)==0){
Algorithm::size = s.st_size;
}
}
bool Algorithm::is_a_folder(std::string path){
struct stat s;
if(stat(path.c_str(),&s)==0){
if(s.st_mode & S_IFDIR){
return true;
}
else return false;
}
return false;
}