函数库.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Microsoft/AllowMicrosoftPlatformTypes.h"
#include "FileWriteAndRead.generated.h"
/**
*
*/
UCLASS()
class SPLINECPP_API UFileWriteAndRead : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static FString ReadFromFile(FString Dir);
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static void WriteToFile(FString FileName,FString content);
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static TArray<FString> FindFiles(FString Patch,FString Filter,bool Files,bool Directory);
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static bool MoveFileTo(FString To,FString From);
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static bool DeleteFile(FString FilePath);
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static void OpenFile(FString FilePath);
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static void CreateDir(FString FilePath);
UFUNCTION(BlueprintCallable,Category = "FileWriteAndRead")
static void DeleteDic(FString FilePath);
};
函数库.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "FileWriteAndRead.h"
#include "HAL/FileManagerGeneric.h"
FString UFileWriteAndRead::ReadFromFile(FString Dir)
{
FString Result;
FFileHelper::LoadFileToString(Result,*(FPaths::ProjectDir()+Dir));
return Result;
}
void UFileWriteAndRead::WriteToFile(FString FileName, FString content)
{
FFileHelper::SaveStringToFile(content,*(FPaths::ProjectDir()+FileName));
}
//查找文件或文件夹
TArray<FString> UFileWriteAndRead::FindFiles(FString Patch, FString Filter, bool Files, bool Directory)
{
TArray<FString> FilePathList;
FilePathList.Empty();
FFileManagerGeneric::Get().FindFilesRecursive(FilePathList,*Patch,*Filter,Files,Directory);
return FilePathList;
}
//移动文件到其他位置
bool UFileWriteAndRead::MoveFileTo(FString To, FString From)
{
return IFileManager::Get().Move(*To,*From);
}
//删除文件
bool UFileWriteAndRead::DeleteFile(FString FilePath)
{
return IFileManager::Get().Delete(*FilePath);
}
//打开文件
void UFileWriteAndRead::OpenFile(FString FilePath)
{
FPlatformProcess::CreateProc(*(FPaths::ProjectDir()+FilePath),nullptr,true,false,false,nullptr,0,nullptr,nullptr);
}
//新建文件夹
void UFileWriteAndRead::CreateDir(FString FilePath)
{
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
}
//删除文件夹
void UFileWriteAndRead::DeleteDic(FString FilePath)
{
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
PlatformFile.DeleteDirectory(*FilePath);
}
文章来源地址https://www.toymoban.com/news/detail-622535.html文章来源:https://www.toymoban.com/news/detail-622535.html
到了这里,关于UE5 c++ 的文件操作(记录备忘)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!