(UE4)查找项目中指定扩展名的文件

例如查找所有地图文件。

static FORCEINLINE TArray<FString> GetAllMapNames()
{
	TArray<FString> mapNames;
	IFileManager::Get().FindFilesRecursive(mapNames, *FPaths::ProjectContentDir(), TEXT("*.umap"), true, false, false);

	for (int32 i = 0; i < mapNames.Num(); i++)
	{
		// replace the whole directory string with only the name of the map

		int32 lastSlashIndex = -1;
		if (mapNames[i].FindLastChar('/', lastSlashIndex))
		{
			FString pureMapName;

			// length - 5 because of the ".umap" suffix
			for (int32 j = lastSlashIndex + 1; j < mapNames[i].Len() - 5; j++)
			{
				pureMapName.AppendChar(mapNames[i][j]);
			}

			mapNames[i] = pureMapName;
		}
	}

	return mapNames;
}

参考:https://answers.unrealengine.com/questions/134539/list-all-maps-in-project-or-directory.html

留下评论