-
Notifications
You must be signed in to change notification settings - Fork 0
/
PathManipuler.cpp
61 lines (50 loc) · 1.36 KB
/
PathManipuler.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
#include "stdafx.h"
#include "PathManipuler.h"
std::vector<fs::path> PathManipuler::FindDirectories(const std::string& searched_dir_name) const
{
std::vector<fs::path> matches;
fs::recursive_directory_iterator it(root_path);
fs::recursive_directory_iterator end;
for(; it != end ; it++)
{
if(fs::is_directory(*it))
{
const std::string& dir_name = it->path().filename().string();
if(dir_name == searched_dir_name)
matches.push_back(*it);
}
}
return matches;
}
fs::path PathManipuler::FindDirectory(const std::string& searched_dir_name) const
{
fs::recursive_directory_iterator it(root_path);
fs::recursive_directory_iterator end;
for(; it != end ; it++)
{
if(fs::is_directory(*it))
{
const std::string& dir_name = it->path().filename().string();
if(dir_name == searched_dir_name)
return *it;
}
}
return root_path;
}
std::vector<fs::path> PathManipuler::FindFiles(const fs::path& search_path, const std::string& searched_extension) const
{
std::vector<fs::path> matches;
fs::recursive_directory_iterator it(search_path);
fs::recursive_directory_iterator end;
for(; it != end ; it++)
{
if(fs::is_regular_file(*it))
{
std::string file_name = it->path().filename().string();
std::string extension = it->path().extension().string();
if(extension == searched_extension)
matches.push_back(*it);
}
}
return matches;
}