I've been trying to figure this out for a while.
How can I make a copy of a directory_entry variable but as a string data type?
A stack overflow post mentioned using the .string() method but using the format below it did not work:
std::string strVar = directEntryVar.string();
Also the directory_entry cppreference page doesn't say anything about it as far as I can see:
https://en.cppreference.com/w/cpp/filesystem/directory_entry
In summary, this function & it's child functions are opening many different files in the directory and opening them, storing data into program, closing the input files, then opening output files, and outputting the stored data of the program into the output files.
For Example, let's say the input file has:
"The:Code" { is great }
{ { "random gibberish" } } |
Then the output file would be:
"The:Code"
"random gibberish" |
Parent Function I'm referring to:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void openFiles() {
// 1.
fs::path fullInPath = fs::current_path();
fullInPath /= "InputFiles";
// 2.
for (const fs::directory_entry &inputFilename : fs::directory_iterator(fullInPath)) {
// 2a.
std::vector<std::string> alphaNums = {};
// ----------------------------------------------
// <No algorithm step in comments for this yet.>
// Goal: Copy "InputFiles/<currentFileNameHere>" to a string so I can use it in argument functions as a string.
std::string inputFilesLocStr = "InputFiles/";
inputFilesLocStr += inputFilename;
// ^ **Trying to make it add the filename to the str**
// ----------------------------------------------
// 2b.
readInputFile(inputFilename, alphaNums);
// 2c.
writeToOutputFile(inputFilename, alphaNums);
}
}
|
Help would be greatly appreciated.
Please Note: I hope you can help me without looking at my full code, as it's probably a mess atm. However, if you absolutely need to see my full code then this is it at the moment:
(Also the notes are mainly for me but you may find them useful)
https://pastebin.com/B25sGHC0
I put it in a pastebin because it didn't fit in this post (length limit) & cpp.sh doesn't compile it because it requires C++17.
Edit: Going to sleep for tonight. I hope to see this tomorrow but it may take me a few days depending how busy school is.