Download

how to get map list from a pak file

i want to get all maps from DLCs.
i did google a lot,but i didt found the answer.
https://answers.unrealengine.com/questions/356347/enumerate-maps-in-folder-with-blueprints.html
the thread above could not get map list from DLC
please help.

here is my code to list all maps in a game,(the dlc map is under the plugin’s Content folder),but this is ugly:

TArray<FString> UYunTuLibraryBPLibrary::GetDLCLists()
{
TArray<FString> MapList;

auto ObjectLibrary = UObjectLibrary::CreateLibrary(UWorld::StaticClass(), false, true);
ObjectLibrary-&gt;LoadAssetDataFromPath(TEXT("/Game/Maps"));
TArray&lt;FAssetData&gt; AssetDatas;
ObjectLibrary-&gt;GetAssetDataList(AssetDatas);

TArray&lt;FString&gt; Names = TArray&lt;FString&gt;();

for (int32 i = 0; i &lt; AssetDatas.Num(); ++i)
{
	FAssetData& AssetData = AssetDatas*;

	auto name = AssetData.AssetName.ToString();
	MapList.Add(name);
}

bool bSuccessfulInitialization = false;

IPlatformFile* LocalPlatformFile = &FPlatformFileManager::Get().GetPlatformFile();

if (LocalPlatformFile != nullptr)
{
	IPlatformFile* PakPlatformFile = FPlatformFileManager::Get().GetPlatformFile(TEXT("PakFile"));
	if (PakPlatformFile != nullptr)
		bSuccessfulInitialization = true;
}

if (bSuccessfulInitialization)
{
	const TCHAR* cmdLine = TEXT("");
	FPakPlatformFile* PakPlatform = new FPakPlatformFile();
	IPlatformFile* InnerPlatform = LocalPlatformFile;
	PakPlatform-&gt;Initialize(InnerPlatform, cmdLine);
	FPlatformFileManager::Get().SetPlatformFile(*PakPlatform);

	TArray&lt;FString&gt; Files;
	Files = GetAllFilesInDirectory("Content/Paks/Mod/", true, "", "pak", true);

	UE_LOG(LogTemp, Warning, TEXT("Mod Path:%s"), *(FPaths::GameDir() + "Content/Paks/Mod/"));

	UE_LOG(LogTemp, Warning, TEXT("Pak File Num:%d"), Files.Num());

	for (FString FilePath : Files)
	{
		FPakFile PakFile(*FilePath, false);

		if (!PakFile.IsValid())
		{
			continue;
		}

		TArray&lt;FString&gt; Keys;
		FString ContentKey;
		PakFile.GetIndex().GenerateKeyArray(Keys);
		for (int i = 0; i &lt; Keys.Num(); i++)
		{
			if (Keys*.Contains("Content"))
			{
				ContentKey = Keys*;
				break;
			}
		}

		auto MapName = PakFile.GetIndex()[ContentKey];
		MapName.GenerateKeyArray(Keys);
		for (FString Temp : Keys)
		{
			Temp = FPaths::GetBaseFilename(Temp);
			MapList.Add(Temp);
		}
	}
}
return MapList;

}