-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (39 loc) · 1.26 KB
/
main.cpp
File metadata and controls
56 lines (39 loc) · 1.26 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
#include <iostream>
#include <string>
#include <vector>
#include <filesystem>
#include <sstream>
struct FileInfo
{
std::wstring filename; // use w string casue win has many file name in hind and other language
std::wstring filepath;
};
int main() {
std::string targetFolder{};
std::cout << "User Add The Folder To Scan-"; // -
std::getline(std::cin, targetFolder);
std::vector<FileInfo> file{};
//! safely report errors
std::error_code errorbyfilesystem;
// how the iterator will work
auto option{ std::filesystem::directory_options::skip_permission_denied };
auto start{ std::filesystem::recursive_directory_iterator(targetFolder , option , errorbyfilesystem) };
auto end{ std::filesystem::recursive_directory_iterator() }; // ! this is the end point we wan't the start to be like this (mean that all file are pushed)
while (start != end) {
// ! if no error find
if (!errorbyfilesystem) {
FileInfo tempFile;
tempFile.filename = start->path().filename().wstring(); //
tempFile.filepath = start->path().wstring();
file.push_back(tempFile);
}
start.increment(errorbyfilesystem);
}
if (file.size() == 0) {
std::cerr << "Error(Use Real File Location)";
}
else {
std::cout << "File Size-" << file.size();
}
return 0;
}