Agrarsense
Static Public Member Functions | List of all members
UFileUtilities Class Reference

#include <FileUtilities.h>

Inheritance diagram for UFileUtilities:
Inheritance graph
[legend]
Collaboration diagram for UFileUtilities:
Collaboration graph
[legend]

Static Public Member Functions

static void OpenFileExplorer (FString Path)
 
static FString OpenFileDialogReturnFirst (const FString &Path)
 
static TArray< FString > OpenFileDialogReturnFiles (const FString &Path)
 

Detailed Description

A class for file related utilities.

Definition at line 17 of file FileUtilities.h.

Member Function Documentation

◆ OpenFileDialogReturnFiles()

TArray< FString > UFileUtilities::OpenFileDialogReturnFiles ( const FString &  Path)
static

Opens a file dialog to allow the user to select multiple files. Note: This function pauses the entire game while the file dialog is open.

Parameters
PathThe initial path to start the file dialog from.
Returns
An array of full paths of the selected files, or an empty array if no files were selected or the operation was canceled.

Definition at line 36 of file FileUtilities.cpp.

37{
38 TArray<FString> OutFiles;
39
40 // OpenFileDialog doesn't work in packaged builds.
41#if !WITH_EDITOR
42 return OutFiles;
43#endif
44
45 IDesktopPlatform* DesktopPlatform = FDesktopPlatformModule::Get();
46 if (!DesktopPlatform)
47 {
48 return OutFiles;
49 }
50
51 FString DefaultPath = Path.IsEmpty() ? FPaths::ProjectDir() : Path;
52
53 // Create a file picker dialog
54 bool bOpened = DesktopPlatform->OpenFileDialog(
55 nullptr,
56 NSLOCTEXT("FileUtilities", "OpenFileDialog", "Choose a file").ToString(),
57 DefaultPath,
58 FString(),
59 TEXT("All Files (*.*)|*.*"),
60 EFileDialogFlags::Multiple,
61 OutFiles
62 );
63
64 if (bOpened)
65 {
66 for (FString& FilePath : OutFiles)
67 {
68 // Convert relative path to full path
69 FilePath = FPaths::ConvertRelativePathToFull(FilePath);
70 }
71 }
72
73 return OutFiles;
74}

Referenced by OpenFileDialogReturnFirst().

◆ OpenFileDialogReturnFirst()

FString UFileUtilities::OpenFileDialogReturnFirst ( const FString &  Path)
static

Opens a file dialog to allow the user to select a file. Note: This function pauses the entire game while the file dialog is open.

Parameters
PathThe initial path to start the file dialog from.
Returns
The full path of the selected file, or an empty string if no file was selected or the operation was canceled.

Definition at line 23 of file FileUtilities.cpp.

24{
25 FString File;
26 TArray<FString> Files = OpenFileDialogReturnFiles(Path);
27
28 if (!Files.IsEmpty())
29 {
30 File = Files[0];
31 }
32
33 return File;
34}
static TArray< FString > OpenFileDialogReturnFiles(const FString &Path)

References OpenFileDialogReturnFiles().

◆ OpenFileExplorer()

void UFileUtilities::OpenFileExplorer ( FString  Path)
static

Opens the file explorer at the specified path.

Parameters
PathThe path to open in the file explorer.

Definition at line 14 of file FileUtilities.cpp.

15{
16 FString AbsolutePath = FPaths::ConvertRelativePathToFull(Path);
17 if (FPaths::DirectoryExists(AbsolutePath))
18 {
19 FPlatformProcess::ExploreFolder(*AbsolutePath);
20 }
21}

Referenced by ULogFile::OpenFilePath().


The documentation for this class was generated from the following files: