-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_file.h
More file actions
32 lines (28 loc) · 1.02 KB
/
random_file.h
File metadata and controls
32 lines (28 loc) · 1.02 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
#include <cstdlib>
#include <iostream>
#include <string>
#include <string_view>
#include <vector>
#include <filesystem>
#include <random>
using namespace std::filesystem;
std::vector<std::string> get_files(std::string_view path_) {
std::vector<std::string> files;
for (auto& entry : directory_iterator(path(path_)))
if (entry.is_regular_file())
files.push_back(entry.path().string());
return files;
}
std::string random_my_rust_lib_file() {
auto files = get_files("C:/code/my_cpp_lib/src/");
std::mt19937 rng(std::random_device{}());
std::uniform_int_distribution<size_t> dist(0, files.size() - 1);
return files[dist(rng)];
}
void open_vscode(std::string_view file) {
auto pos = file.find("code");
std::string file_name = std::string(file.substr(pos + 4));
std::cout << "\n-- opening file " << file_name << " ...\n";
std::string cmd = "\"\"C:\\Users\\gokha\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\" \"" + std::string(file) + "\"\"";
std::system(cmd.c_str());
}