List all folders in a folder

Hi guys, i used this code

TArray<FString> UFileFunctionLibrary::GetValidDirectories(const FString& Directory)
	TArray<FString> FoundFolders;
	if (FPaths::DirectoryExists(Directory))
		FFileManagerGeneric::Get().FindFiles(FoundFolders, *Directory, false, true);
		for (int i = 0; i < FoundFolders.Num(); i++)
			FoundFolders[i] = Directory + FoundFolders[i];
			UE_LOG(LogTemp, Warning, TEXT("Found Folder: %s"), *FoundFolders[i]);
return FoundFolders;

and it only returns folder name in “Directory” path. Nothing else. What did i do wrong/How should i do it?

1 Like

FFileManagerGeneric::FindFiles does not return files in sub-directories. Use FFileManagerGeneric::FindFilesRecursive instead.

That didn’t work. I tried

FFileManagerGeneric::Get().FindFilesRecursive(FoundFolders, *Directory, *Directory, false, true, true);

and it did just the same as code above

1 Like

Try this:

FFileManagerGeneric::Get().FindFilesRecursive(FoundFolders, *Directory, TEXT("*"), false, true, true);

The third parameter acts as a filter.


Actually that does work! Thank you!