Hello!
I’ve create a simple game which offers the player a widget were he can type down some text and them saves it to a file.
It’s working fine, the only problem is that the files gets replaced instead of appended and I’m not being able to figure out how to append. Can you guys help me out?
Here is my code: .h
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Paths.h"
#include "WriteToFile.generated.h"
/**
*
*/
UCLASS()
class UWriteToFile : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintCallable, meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject", FriendlyName = "File-IO"), Category = "WriteToFile")
static bool FileIO__SaveStringTextToFile(FString SaveDirectory, FString fileName, FString SaveText, bool AllowOverWriting);
};
Code: .cpp
#include "WriteToFile.h"
UWriteToFile::UWriteToFile(const class FObjectInitializer& PCIP)
:Super(PCIP)
{
}
bool UWriteToFile::FileIO__SaveStringTextToFile(FString SaveDirectory, FString fileName, FString SaveText, bool AllowOverWriting)
{
FString path;
path = FPaths::GameDir();
path += "/Questions";
if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*path))
{
FPlatformFileManager::Get().GetPlatformFile().CreateDirectory(*path);
if (!FPlatformFileManager::Get().GetPlatformFile().DirectoryExists(*path))
{
return false;
}
}
path += "/";
path += fileName;
if (!AllowOverWriting)
{
if (FPlatformFileManager::Get().GetPlatformFile().FileExists(*path))
{
return false;
}
}
return FFileHelper::SaveStringToFile(SaveText, *path);
}
Any idea what I am missing?