How do I get an array of files in a directory?

First, I get all the file names with IFileManager and FindFiles(). The correct file names are returned. Then I try to load all those files and push them into an array.

for (FString fileName : xmlFileNames) {
	GLog->Log("    " + fileName);
	FXmlFile xmlFile(FPaths::Combine(contentFolderPath, fileName)); // load file

	if (xmlFile.IsValid()) {
		xmlFiles.Push(xmlFile);
	}
	else
	{
		GLog->Log("   *** Error: Could not load " + fileName);
	}
}

This doesn’t compile. Here is the error:

C:\Program Files\Epic Games\UE_4.18\Engine\Source\Runtime\Core\Public\Containers/Array.h(1736): error C2248: 'FXmlFile::FXmlFile': cannot access private member declared in class 'FXmlFile'.

How can I get these files into my array? Thanks.

Honestly, I haven’t a clue having never attempted to do this myself before, but I am intrigued enough to attempt to help. After all, I may need it myself in the future!

Which line seems to be generating the compilation error? The line in which you construct the FXmlFile?

I suggest that you ensure the path returned by Combine() is indeed correct. Call it before the constructor and store it in a local variable or something, then you can debug it.
Perhaps try typing in a known path and seeing if that provides you with any more success.

I notice in the documentation that there is a second argument in its constructor. I presume it already has a default value defined, but would the EConstructMethod for some reason affect the accessibility of the class?

Have you also tried using the constructor without arguments, and then using the LoadFile method?

I’m sorry if these are all obvious suggestions, but one has to start somewhere!

I probably should put a more complete error in there. I edited my question. The error is actually in the Array class. Apparently, the array can’t access the private constructor of the FXmlFile object. Pointers will work, but then I just have an array of dangling pointers when the loop ends because the FXmlFile goes out of scope on every iteration.

Yep, file path is correct. I tested a known path just to be sure.

The EConstructMethod would let me put a string of XML into the constructor rather than a file, but that’s not what I need.

I gave the constructor without arguments thing a go but that doesn’t really work either. If I use the new keyword, as in FXmlFile* xmlFile = new FXmlFile();, then I’m left with the pointer problem again. If I don’t use the new keyword, then I’m left with the same error, C2248.

I appreciate the suggestions anyway.

Hmm, I can see your difficulty now. It did seem like a private constructor issue from searching.

There’s no chance you could extract the node data and store that instead?
Perhaps - and this seems like a convoluted approach from the outset - you could store it in your own object and put that in the array instead.
I know that somewhat defeats the purpose of the xml file, but you could still retain its functionality by mimicking it. Depending on your situation - you might even be able to add functionality to suit your program.

In the past, I’ve often stored information loaded at runtime in structs, which seems to work okay for many situations.

Sorry I can’t be of more help ^^’
It’s a topic I’m mildly interested in, but I’ve yet to find a need for it.
The documentation also seems a little scarce on the subject, which doesn’t help anyone.