FileManager::FindFiles() overload fails to find files or directories

I want a function that when given a path, it will return a list of folder names that are inside that path. I already use

FileManager.FindFiles(Files, *FinalPath, NULL);

to find a list of all files inside of a folder and it works. But the overload function is not working.

I have the code in a blueprint library

bool UMusicalRangeBPFunctionLibrary::LoadFromFileGetAvailableFolders(TArray<FString>& Folders, FString FullFilePath, bool printFolders) {
	FPaths::NormalizeDirectoryName(FullFilePath);
	IFileManager& FileManager = IFileManager::Get();

	FileManager.FindFiles(Folders, *FullFilePath, true, true);

	if (printFolders)
	{
		for (int i = 0; i < Folders.Num(); i++)
		{
			UE_LOG(LogMusicalRange, Log, TEXT("File Found: %s"), *Folders[i]);
		}
	}
	return true;
}

In the blueprint then I give it a directory like in the picture, and when I mouse over the result, it just gives me the name of the last folder I input.

https://puu.sh/vjmCe/9da494a386.png

This is the content of the folder and what I expect to see in the array list.

https://puu.sh/vjmEt/81257341a2.png

Yes. This is how you use the function. Basically, you want your path to look something like

 "D:/SteamLibrary/SteamApps/common/Musical Range/MusicalRange/Content/CustomSongs/*"

Normalize will change “” to “/”, and then the

bool UMusicalRangeBPFunctionLibrary::LoadFromFileGetAvailableFolders(TArray<FString>& Folders, FString FullFilePath, bool printFolders) {
	FPaths::NormalizeDirectoryName(FullFilePath);
	IFileManager& FileManager = IFileManager::Get();

	FullFilePath = FullFilePath / "*";
	UE_LOG(LogMusicalRange, Log, TEXT("FullFilePath: %s"), *FullFilePath);
	FileManager.FindFiles(Folders, *FullFilePath, false, true);

	if (printFolders)
	{
		for (int i = 0; i < Folders.Num(); i++)
		{
			UE_LOG(LogMusicalRange, Log, TEXT("File Found: %s"), *Folders[i]);
		}
	}
	return true;
}
1 Like

Yes! I just posted the answer with the full code to get it running on Blueprints.

man, i’ve been seeing you everywhere this week. did you ever figure this out? i’m having the same issue. FindFiles just doesn’t return directories for some reason