IDesktopPlatform
Open Explorer for browsing files on PC drive and return path of selected file
.h
#if WITH_EDITOR
/**
* Open Browsing Dialog in PC
*/
UFUNCTION(BlueprintCallable, Category="Import")
static FString BrowseFiles(FString PromptMessage, bool& bOutSuccess, FString& OutInfoMsg);
#endif
.cpp
#if WITH_EDITOR
#include "IDesktopPlatform.h"
#include "DesktopPlatformModule.h"
FString UImportAsset::BrowseFiles(FString PromptMessage, bool& bOutSuccess, FString& OutInfoMsg)
{
bool bOpen = false;
TArray<FString> OpenFilenames;
FString ExtensionStr;
ExtensionStr += TEXT("CSV files|*.csv|");
IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
if (!DesktopPlatform){
bOutSuccess = false;
OutInfoMsg = FString::Printf(TEXT("Browsing files is supported on Desktop platform only - Please, fill the paths manually."));
return FString();
}
FString DefaultPath;
FString DefaultFile;
FString PickedFileName;
bOpen = DesktopPlatform->OpenFileDialog(
FSlateApplication::Get().FindBestParentWindowHandleForDialogs(nullptr),
*PromptMessage,
*DefaultPath,
*DefaultFile,
*ExtensionStr,
EFileDialogFlags::None, // allow select only one
OpenFilenames
);
if (bOpen)
{
bOutSuccess = (OpenFilenames.Num() == 1);
if(bOutSuccess) PickedFileName = OpenFilenames[0];
}
return PickedFileName;
}
#endif
.Build.cs
if (Target.bBuildEditor == true)
{
PublicDependencyModuleNames.AddRange(
new string[]
{
"DesktopPlatform",
}
);
}