Bootstrap

UE4获取指定目录下所有文件

 

 

FString strBasePath = FPaths::Combine(*FPaths::ProjectDir(), TEXT("Content/")); 
FString allUIFilePath = FPaths::Combine(*strBasePath, TEXT("UI/Wnd/")); 
TArray<FString> allWndFilePath;
IFileManager::Get().FindFilesRecursive(allWndFilePath, *allUIFilePath, TEXT("*.uasset"), true, false);

 

allUIFilePath = “../../../../ProjectDir/Content/UI/Wnd/TestWnd.uasset”

通过找到最后一个/和最后一个.字符可以获得文件名TestWnd

 

		tempPath.FindLastChar('/', iFindStart);
		tempPath.FindLastChar('.', iFindEnd);
		FString strFileName = tempPath.Mid(iFindStart + 1, iFindEnd - iFindStart - 1);

 

可用于加载UObject的路径为

 

		FString LoadObjectPath= tempPath.Replace(*strBasePath, TEXT("/Game/")).Replace(TEXT(".uasset"), *FString::Printf(TEXT(".%s"), *strFileName))
实例:/Game/UI/Wnd/TestWnd.TestWnd

 

可用于加载UClass的路径为

 

		FString LoadObjectPath= tempPath.Replace(*strBasePath, TEXT("/Game/")).Replace(TEXT(".uasset"), *FString::Printf(TEXT(".%s"), *strFileName)) + "_C";
实例:/Game/UI/Wnd/TestWnd.TestWnd_C

 

 

;