forked from 0JIEUN0/FileSearcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_find_file.cpp
More file actions
82 lines (75 loc) · 2.66 KB
/
demo_find_file.cpp
File metadata and controls
82 lines (75 loc) · 2.66 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
/**
* DEMO for Finding file using FULL String Match.
* Copyright (C) 2020 KangDroid, aka Jason. HW. Kang
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <filesystem>
#include <vector>
using namespace std;
/**
* argc: Count of Args are stored
* argv: "C-String List"
*
* First of argument is "Execution name"
*/
int main(int argc, char** argv) {
vector<string> path_container;
if (argc < 2) {
// There is no file name || target find directory from argument.
return -1;
}
// C-String to CPP-String[File Name]
string file_name = string(argv[1]);
string target_directory = string(argv[2]);
/**
* Use Auto && Follow latest CPP reference
* Also, push FULL ABSOLUTE path to vector
*/
for (auto& iterator : filesystem::directory_iterator(target_directory)) {
path_container.push_back(string(iterator.path()));
}
/**
* Print Absolute Directores
* either for (int i = 0; i < path_container.size(); i++) ...
*/
cout << "Full Path" << endl;
for (string iterator : path_container) {
cout << iterator << endl;
}
cout << endl;
/**
* Print Relative Path
*/
cout << "Relative Path(Subsituting Absolute Path)" << endl;
for (string string_manip : path_container) {
// The "Real file name", subsituting absolute path
string file_name_found = string_manip.substr(target_directory.length()+1, (string_manip.length() - target_directory.length()));
cout << file_name_found << endl;
}
cout << endl;
/**
* Find File Name[Full String Match] and print absolute/relatie path
*/
for (string to_work : path_container) {
string file_name_found = to_work.substr(target_directory.length()+1, (to_work.length() - target_directory.length()));
if (file_name_found == file_name) {
cout << "Found File, matching: " << file_name << endl;
cout << "Absolute path: " << to_work << endl;
cout << "Relative path: " << file_name_found << endl;
}
}
return 0;
}