UE4对本地文件的操作首先是文件的读写 .h UFUNCTION(BlueprintCallable, Category = "File operation") static FString ReadStringToFile(FString Dir); UFUNCTION(BlueprintCallable, Category = "File operation") static void WriteStringToFile(FString FileName, FString content);.cpp FString ACPP_Test::ReadStringToFile(FString Dir){ FString Result; FFileHelper::LoadFileToString(Result, *Dir); return Result;}void ACPP_Test::WriteStringToFile(FString FileName, FString content){ FFileHelper::SaveStringToFile(content, *FileName);}查找文件或者文件夹#include "Runtime/Core/Public/HAL/FileManagerGeneric.h".h UFUNCTION(BlueprintCallable, Category = "File operation") static TArray<FString> FindFiles(FString Path, FString Filter, bool Files, bool Directory);.cpp TArray<FString> ACPP_Test::FindFiles(FString Path, FString Filter, bool Files, bool Directory){ TArray<FString> FilePathList; FilePathList.Empty(); FFileManagerGeneric::Get().FindFilesRecursive(FilePathList, *Path, *Filter, Files, Directory); return FilePathList;}指定文件移动到某处(修改文件路径)#include "Runtime/Core/Public/HAL/FileManagerGeneric.h".h UFUNCTION(BlueprintCallable, Category = "File operation") static bool MoveFileTo(FString To, FString From);.cpp bool ACPP_Test::MoveFileTo(FString To, FString From){ return IFileManager::Get().Move(*To, *From);}删除指定文件#include "Runtime/Core/Public/HAL/FileManagerGeneric.h".h UFUNCTION(BlueprintCallable, Category = "File operation") static bool DeleteFile(FString FilePath);.cpp bool ACPP_Test::DeleteFile(FString FilePath){ return IFileManager::Get().Delete(*FilePath);}打开指定文件#include "Runtime/Core/Public/HAL/FileManagerGeneric.h".h UFUNCTION(BlueprintCallable, Category = "File operation") static void OpenFile(FString FilePath);.cpp void ACPP_Test::OpenFile(FString FilePath){ FPlatformProcess::CreateProc(*FilePath, nullptr, true, false, false, nullptr, 0, nullptr, nullptr);}创建文件夹.h UFUNCTION(BlueprintCallable, Category = "File operation") static void CreateDic(FString filePath);.cpp void ACPP_Test::CreateDic(FString filePath){ IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); PlatformFile.CreateDirectory(*filePath);}删除文件夹.h UFUNCTION(BlueprintCallable, Category = "File operation") static void DeleteDic(FString filePath);.cpp void ACPP_Test::DeleteDic(FString filePath){ IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile(); PlatformFile.DeleteDirectory(*filePath);}
|
|