forked from VILLASframework/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
45 lines (40 loc) · 1.17 KB
/
utils.cpp
File metadata and controls
45 lines (40 loc) · 1.17 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
/* Utils
*
* Author: Pascal Bauer <pascal.bauer@rwth-aachen.de>
*
* SPDX-FileCopyrightText: 2023-2024 Pascal Bauer <pascal.bauer@rwth-aachen.de>
* SPDX-License-Identifier: Apache-2.0
*/
#include <filesystem>
#include <fstream>
#include <iostream>
#include <villas/fpga/devices/utils.hpp>
#include <villas/log.hpp>
#include <dirent.h>
void write_to_file(std::string data, const std::filesystem::path file) {
villas::logging.get("Filewriter")->debug("{} > {}", data, file.u8string());
std::ofstream outputFile(file.u8string());
if (outputFile.is_open()) {
// Write to file
outputFile << data;
outputFile.close();
} else {
throw std::filesystem::filesystem_error("Cannot open outputfile",
std::error_code());
}
}
std::vector<std::string> read_names_in_directory(const std::string &name) {
DIR *directory = opendir(name.c_str());
struct dirent *dp;
std::vector<std::string> names;
dp = readdir(directory);
while (dp != NULL) {
auto name = std::string(dp->d_name);
if (name != "." && name != "..") {
names.push_back(name);
}
dp = readdir(directory);
}
closedir(directory);
return names;
}