UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FFileHelper Struct Reference

#include <FileHelper.h>

Public Types

enum class  EHashOptions { None =0 , EnableVerify =1<<0 , ErrorMissingHash =1<<1 }
 
enum class  EEncodingOptions {
  AutoDetect , ForceAnsi , ForceUnicode , ForceUTF8 ,
  ForceUTF8WithoutBOM
}
 
enum class  EColorChannel {
  R , G , B , A ,
  All
}
 

Public Member Functions

enum UE_DEPRECATED (5.0, "EChannelMask has been deprecated in favor of EColorChannel") EChannelMask
 

Static Public Member Functions

static CORE_API void BufferToString (FString &Result, const uint8 *Buffer, int32 Size)
 
static CORE_API bool LoadFileToArray (TArray< uint8 > &Result, const TCHAR *Filename, uint32 Flags=0)
 
static CORE_API bool LoadFileToArray (TArray64< uint8 > &Result, const TCHAR *Filename, uint32 Flags=0)
 
static CORE_API bool LoadFileInBlocks (FStringView Filename, TFunctionRef< void(FMemoryView)> BlockVisitor, int64 Offset=0, int64 Size=-1, uint32 Flags=0, int64 BlockSize=0)
 
static CORE_API bool LoadFileToString (FString &Result, FArchive &Reader, EHashOptions VerifyFlags=EHashOptions::None)
 
static CORE_API bool LoadFileToString (FString &Result, const TCHAR *Filename, EHashOptions VerifyFlags=EHashOptions::None, uint32 ReadFlags=0)
 
static CORE_API bool LoadFileToString (FString &Result, IPlatformFile *PlatformFile, const TCHAR *Filename, EHashOptions VerifyFlags=EHashOptions::None, uint32 ReadFlags=0)
 
static CORE_API bool LoadFileToStringArray (TArray< FString > &Result, const TCHAR *Filename)
 
static CORE_API bool LoadFileToStringArray (TArray< FString > &Result, const TCHAR *Filename, EHashOptions VerifyFlags)
 
static CORE_API bool LoadFileToStringArrayWithPredicate (TArray< FString > &Result, const TCHAR *Filename, TFunctionRef< bool(const FString &)> Predicate)
 
static CORE_API bool LoadFileToStringArrayWithPredicate (TArray< FString > &Result, const TCHAR *Filename, TFunctionRef< bool(const FString &)> Predicate, EHashOptions VerifyFlags)
 
static CORE_API bool LoadFileToStringWithLineVisitor (const TCHAR *Filename, TFunctionRef< void(FStringView Line)> Visitor)
 
static CORE_API bool SaveArrayToFile (TArrayView64< const uint8 > Array, const TCHAR *Filename, IFileManager *FileManager=&IFileManager::Get(), uint32 WriteFlags=0)
 
static CORE_API bool SaveArrayToFile (const TArray64< uint8 > &Array, const TCHAR *Filename, IFileManager *FileManager=&IFileManager::Get(), uint32 WriteFlags=0)
 
static CORE_API bool SaveStringToFile (FStringView String, const TCHAR *Filename, EEncodingOptions EncodingOptions=EEncodingOptions::AutoDetect, IFileManager *FileManager=&IFileManager::Get(), uint32 WriteFlags=0)
 
static CORE_API bool SaveStringArrayToFile (const TArray< FString > &Lines, const TCHAR *Filename, EEncodingOptions EncodingOptions=EEncodingOptions::AutoDetect, IFileManager *FileManager=&IFileManager::Get(), uint32 WriteFlags=0)
 
static CORE_API bool CreateBitmap (const TCHAR *Pattern, int32 DataWidth, int32 DataHeight, const struct FColor *Data, FIntRect *SubRectangle=NULL, IFileManager *FileManager=&IFileManager::Get(), FString *OutFilename=NULL, bool bInWriteAlpha=false, EColorChannel ColorChannel=EColorChannel::All)
 
static CORE_API bool GenerateNextBitmapFilename (const FString &Pattern, const FString &Extension, FString &OutFilename, IFileManager *FileManager=&IFileManager::Get())
 
static CORE_API void GenerateDateTimeBasedBitmapFilename (const FString &Pattern, const FString &Extension, FString &OutFilename)
 
static CORE_API bool LoadANSITextFileToStrings (const TCHAR *InFilename, IFileManager *InFileManager, TArray< FString > &OutStrings)
 
static CORE_API bool IsFilenameValidForSaving (const FString &Filename, FText &OutError)
 
static PRAGMA_DISABLE_DEPRECATION_WARNINGS CORE_API bool CreateBitmap (const TCHAR *Pattern, int32 DataWidth, int32 DataHeight, const struct FColor *Data, FIntRect *SubRectangle, IFileManager *FileManager, FString *OutFilename, bool bInWriteAlpha, EChannelMask ChannelMask)
 

Member Enumeration Documentation

◆ EColorChannel

Enumerator
All 

◆ EEncodingOptions

Enumerator
AutoDetect 
ForceAnsi 
ForceUnicode 
ForceUTF8 
ForceUTF8WithoutBOM 

◆ EHashOptions

Enumerator
None 
EnableVerify 

Enable the async task for verifying the hash for the file being loaded

ErrorMissingHash 

A missing hash entry should trigger an error

Member Function Documentation

◆ BufferToString()

void FFileHelper::BufferToString ( FString &  Result,
const uint8 Buffer,
int32  Size 
)
static

Load a text file to an FString. Supports all combination of ANSI/Unicode files and platforms.

Converts an arbitrary text buffer to an FString. Supports all combination of ANSI/Unicode files and platforms.

◆ CreateBitmap() [1/2]

static PRAGMA_DISABLE_DEPRECATION_WARNINGS CORE_API bool FFileHelper::CreateBitmap ( const TCHAR Pattern,
int32  DataWidth,
int32  DataHeight,
const struct FColor Data,
FIntRect SubRectangle,
IFileManager FileManager,
FString *  OutFilename,
bool  bInWriteAlpha,
EChannelMask  ChannelMask 
)
static

◆ CreateBitmap() [2/2]

static CORE_API bool FFileHelper::CreateBitmap ( const TCHAR Pattern,
int32  DataWidth,
int32  DataHeight,
const struct FColor Data,
FIntRect SubRectangle = NULL,
IFileManager FileManager = &IFileManager::Get(),
FString *  OutFilename = NULL,
bool  bInWriteAlpha = false,
EColorChannel  ColorChannel = EColorChannel::All 
)
static

Saves a 24/32Bit BMP file to disk for debug image dump purposes

for general image saving (to BMP or any other format); use FImageUtils::SaveImage instead CreateBitmap is mainly for debug dump images

note this also calls SendDataToPCViaUnrealConsole and uses GenerateNextBitmapFilename if Pattern does not have ".bmp" on it

Parameters
Patternfilename with path, must not be 0, if with "bmp" extension (e.g. "out.bmp") the filename stays like this, if without (e.g. "out") automatic index numbers are addended (e.g. "out00002.bmp")
DataWidth- Width of the bitmap supplied in Data >0
DataHeight- Height of the bitmap supplied in Data >0
Datamust not be 0
SubRectangleoptional, specifies a sub-rectangle of the source image to save out. If NULL, the whole bitmap is saved
FileManagermust not be 0
OutFilenameoptional, if specified filename will be output
bInWriteAlphaoptional, specifies whether to write out the alpha channel. Will force BMP V4 format.
ColorChanneloptional, specifies a specific channel to write out (will be written out to all channels gray scale).
Returns
true if success

◆ GenerateDateTimeBasedBitmapFilename()

void FFileHelper::GenerateDateTimeBasedBitmapFilename ( const FString &  Pattern,
const FString &  Extension,
FString &  OutFilename 
)
static

Generates the next unique bitmap filename with a specified extension

Parameters
PatternFilename with path, but without extension.
ExtensionFile extension to be appended
OutFilenameReference to an FString where the newly generated filename will be placed
Returns
true if success

Generates the next unique bitmap filename with a specified extension

Parameters
PatternFilename with path, but without extension. @oaran Extension File extension to be appended
OutFilenameReference to an FString where the newly generated filename will be placed
Returns
true if success

◆ GenerateNextBitmapFilename()

bool FFileHelper::GenerateNextBitmapFilename ( const FString &  Pattern,
const FString &  Extension,
FString &  OutFilename,
IFileManager FileManager = &IFileManager::Get() 
)
static

Generates the next unique bitmap filename with a specified extension

Parameters
PatternFilename with path, but without extension.
ExtensionFile extension to be appended
OutFilenameReference to an FString where the newly generated filename will be placed
FileManagerReference to a IFileManager (or the global instance by default)
Returns
true if success

Generates the next unique bitmap filename with a specified extension

Parameters
PatternFilename with path, but without extension. @oaran Extension File extension to be appended
OutFilenameReference to an FString where the newly generated filename will be placed
FileManagerReference to a IFileManager (or the global instance by default)
Returns
true if success

◆ IsFilenameValidForSaving()

bool FFileHelper::IsFilenameValidForSaving ( const FString &  Filename,
FText OutError 
)
static

Checks to see if a filename is valid for saving. A filename must be under FPlatformMisc::GetMaxPathLength() to be saved

Parameters
FilenameFilename, with or without path information, to check.
OutErrorIf an error occurs, this is the reason why

◆ LoadANSITextFileToStrings()

bool FFileHelper::LoadANSITextFileToStrings ( const TCHAR InFilename,
IFileManager InFileManager,
TArray< FString > &  OutStrings 
)
static

Load the given ANSI text file to an array of strings - one FString per line of the file. Intended for use in simple text parsing actions

Parameters
InFilenameThe text file to read, full path
InFileManagerThe filemanager to use - NULL will use &IFileManager::Get()
OutStringsThe array of FStrings to fill in
Returns
bool true if successful, false if not

◆ LoadFileInBlocks()

bool FFileHelper::LoadFileInBlocks ( FStringView  Filename,
TFunctionRef< void(FMemoryView)>  BlockVisitor,
int64  Offset = 0,
int64  Size = -1,
uint32  Flags = 0,
int64  BlockSize = 0 
)
static

Load a binary file a block at a time into a buffer and call the visitor each time the buffer is populated with a new block. This uses less memory and has higher cache coherency than loading the entire file into a block of bytes, and is more performant than reading the file a byte at a time. Useful for e.g. hashing or parsing.

Parameters
FilenameThe file to read
BlockVisitorFunction called repeatedly with each sequential block. Size of the input might change for performance and should not be assumed. Possibly the entire file will be passed in a single block. If LoadFileInBlocks returns true, the sum of sizes in each call to BlockVisitor equals the size of the requested range of the the file on disk. If the requested range has size 0, LoadFileInBlocks will return true and the BlockVisitor will not be called.
OffsetStart of the range of bytes to read from the file. If less than zero or larger than filesize, it will be silently clamped to the [0,FileSize] range. This may result in LoadFileInBlocks returning true but using an empty range and not calling BlockVisitor.
Lengthof the range of bytes to read from the file. If less than zero, all bytes between Offset and end of file are read. If larger than the size of the range between Offset and end of file, it will be silently shortened to the size of the range.
FlagsFlags to pass to IFileManager::CreateFileReader
BlockSizeSize of the internally-allocated buffer to read bytes into and pass to each call to BlockVisitor. Sizes <= 0 use the default-selected block size for the current platform.

◆ LoadFileToArray() [1/2]

bool FFileHelper::LoadFileToArray ( TArray64< uint8 > &  Result,
const TCHAR Filename,
uint32  Flags = 0 
)
static

Load a binary file to a dynamic array with two uninitialized bytes at end as padding.

Parameters
ResultReceives the contents of the file
FilenameThe file to read
FlagsFlags to pass to IFileManager::CreateFileReader

Load a binary file to a dynamic array with two uninitialized bytes at end as padding. TArray64 version.

◆ LoadFileToArray() [2/2]

bool FFileHelper::LoadFileToArray ( TArray< uint8 > &  Result,
const TCHAR Filename,
uint32  Flags = 0 
)
static

Load a binary file to a dynamic array with two uninitialized bytes at end as padding.

Parameters
ResultReceives the contents of the file
FilenameThe file to read
FlagsFlags to pass to IFileManager::CreateFileReader

Load a binary file to a dynamic array with two uninitialized bytes at end as padding.

◆ LoadFileToString() [1/3]

bool FFileHelper::LoadFileToString ( FString &  Result,
const TCHAR Filename,
EHashOptions  VerifyFlags = EHashOptions::None,
uint32  ReadFlags = 0 
)
static

Load a text file to an FString. Supports all combination of ANSI/Unicode files and platforms.

Parameters
ResultString representation of the loaded file
FilenameName of the file to load
VerifyFlagsFlags controlling the hash verification behavior ( see EHashOptions )

Load a text file to an FString. Supports all combination of ANSI/Unicode files and platforms.

Parameters
Resultstring representation of the loaded file
Filenamename of the file to load
VerifyFlagsflags controlling the hash verification behavior ( see EHashOptions )

◆ LoadFileToString() [2/3]

bool FFileHelper::LoadFileToString ( FString &  Result,
FArchive Reader,
EHashOptions  VerifyFlags = EHashOptions::None 
)
static

Loads a text file from an FArchive to an FString. Supports all combination of ANSI/Unicode files and platforms.

Parameters
ResultString representation of the loaded file
ReaderThe archive to load from
VerifyFlagsFlags controlling the hash verification behavior ( see EHashOptions )

◆ LoadFileToString() [3/3]

bool FFileHelper::LoadFileToString ( FString &  Result,
IPlatformFile PlatformFile,
const TCHAR Filename,
EHashOptions  VerifyFlags = EHashOptions::None,
uint32  ReadFlags = 0 
)
static

Load a text file to an FString. Supports all combination of ANSI/Unicode files and platforms.

Parameters
ResultString representation of the loaded file
PlatformFilePlatformFile interface to use
FilenameName of the file to load
VerifyFlagsFlags controlling the hash verification behavior ( see EHashOptions )

◆ LoadFileToStringArray() [1/2]

bool FFileHelper::LoadFileToStringArray ( TArray< FString > &  Result,
const TCHAR Filename 
)
static

Load a text file to an array of strings. Supports all combination of ANSI/Unicode files and platforms.

Parameters
ResultString representation of the loaded file
FilenameName of the file to load

◆ LoadFileToStringArray() [2/2]

bool FFileHelper::LoadFileToStringArray ( TArray< FString > &  Result,
const TCHAR Filename,
EHashOptions  VerifyFlags 
)
static

◆ LoadFileToStringArrayWithPredicate() [1/2]

bool FFileHelper::LoadFileToStringArrayWithPredicate ( TArray< FString > &  Result,
const TCHAR Filename,
TFunctionRef< bool(const FString &)>  Predicate 
)
static

Load a text file to an array of strings, filtered by a user-defined predicate. Supports all combination of ANSI/Unicode files and platforms.

Parameters
ResultString representation of the loaded file
FilenameName of the file to load
PredicateCondition for whether or not to add the line to the array

◆ LoadFileToStringArrayWithPredicate() [2/2]

bool FFileHelper::LoadFileToStringArrayWithPredicate ( TArray< FString > &  Result,
const TCHAR Filename,
TFunctionRef< bool(const FString &)>  Predicate,
EHashOptions  VerifyFlags 
)
static

◆ LoadFileToStringWithLineVisitor()

bool FFileHelper::LoadFileToStringWithLineVisitor ( const TCHAR Filename,
TFunctionRef< void(FStringView Line)>  Visitor 
)
static

Load a text file and invoke a visitor for each line. Supports all combination of ANSI/Unicode files and platforms.

Parameters
FilenameName of the file to load
VisitorVisitor to invoke for each non-empty line in the file

◆ SaveArrayToFile() [1/2]

bool FFileHelper::SaveArrayToFile ( const TArray64< uint8 > &  Array,
const TCHAR Filename,
IFileManager FileManager = &IFileManager::Get(),
uint32  WriteFlags = 0 
)
static

Save a binary array to a file.

◆ SaveArrayToFile() [2/2]

bool FFileHelper::SaveArrayToFile ( TArrayView64< const uint8 Array,
const TCHAR Filename,
IFileManager FileManager = &IFileManager::Get(),
uint32  WriteFlags = 0 
)
static

Save a binary array to a file.

◆ SaveStringArrayToFile()

bool FFileHelper::SaveStringArrayToFile ( const TArray< FString > &  Lines,
const TCHAR Filename,
EEncodingOptions  EncodingOptions = EEncodingOptions::AutoDetect,
IFileManager FileManager = &IFileManager::Get(),
uint32  WriteFlags = 0 
)
static

Write the FString to a file. Supports all combination of ANSI/Unicode files and platforms.

◆ SaveStringToFile()

bool FFileHelper::SaveStringToFile ( FStringView  String,
const TCHAR Filename,
EEncodingOptions  EncodingOptions = EEncodingOptions::AutoDetect,
IFileManager FileManager = &IFileManager::Get(),
uint32  WriteFlags = 0 
)
static

Write the FString to a file. Supports all combination of ANSI/Unicode files and platforms.

◆ UE_DEPRECATED()

enum FFileHelper::UE_DEPRECATED ( 5.  0,
"EChannelMask has been deprecated in favor of EColorChannel"   
)
inlinestrong

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