IFIleManager and IFileManagerGeneric return null for files

Hello unreal poeple
I get some problem here:

code;

TArray<FString> output;
output.Empty();
if (FPaths::DirectoryExists(Directory))
{
	//IFileManager::Get().FindFiles(output, *Directory, true, true);
	
	FFileManagerGeneric::Get().FindFiles(output,*Directory, true, true);
	for (int i = 0; i < output.Num(); i++)
	{
		print(output[i]);
	}
}
return output;

i try to get a list of files inside some folder but this to function just return me the list of folders but not files, is a bug or something? i on 4.7. any suggestions?

finally after 1 hour i get this XD

TArray<FString> UMyStuffAndUtils::getFilesInFolder(FString Directory)
{
	TArray<FString> output;
	output.Empty();
	if (FPaths::DirectoryExists(Directory))
	{
		FString path = Directory + "*.png";
		FFileManagerGeneric::Get().FindFiles(output, *path, true, false);
		for (int i = 0; i < output.Num(); i++)
		{
			output[i] = Directory + output[i];
			print(output[i]);
		}
	}
	return output;
}

well the documentation about dont say nothing especial, i add a FString from my directory + “.ext” wildcard, in this case search for .png images, then the for loop just fix the Absolute path for each. nicely!!

1 Like

That is it!

I changed your code a bit to call it via Blueprint.

For those who want to do this.

You have to create a “new C++ class” that inherits from “Blueprint Function Libary”.

Then you have to add the following code to the .h & the .cpp.

.h:

Add this before you #include “MyBlueprintFunctionLibrary.generated.h”.

#include "HAL/FileManagerGeneric.h"
#include "Misc/Paths.h"

Add this in the UClass definition after GENERATED_BODY() !

public:
	UFUNCTION(BlueprintCallable, Category = FileManager)
		static TArray<FString> getFilesInFolder(FString Directory, FString Extension);

.cpp:

Dont forget to use your classname instead of “UMyBlueprintFunctionLibary”!

TArray<FString> UMyBlueprintFunctionLibrary::getFilesInFolder(FString Directory, FString Extension)
{
	TArray<FString> output;
	output.Empty();
	if (FPaths::DirectoryExists(Directory))
	{
		FString path = Directory + Extension;
		FFileManagerGeneric::Get().FindFiles(output, *path, true, false);
	}
	return output;
}

Compile it and you can call it via Blueprint.


Call getFilesInFolder

1 Like