A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

UE4对本地文件的操作

首先是文件的读写

.h

    UFUNCTION(BlueprintCallable, Category = "File operation")        static FString ReadStringToFile(FString Dir);    UFUNCTION(BlueprintCallable, Category = "File operation")        static void WriteStringToFile(FString FileName, FString content);
  • 1
  • 2
  • 3
  • 4
  • 5

.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);}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
查找文件或者文件夹#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
  • 1

.h

    UFUNCTION(BlueprintCallable, Category = "File operation")        static TArray<FString> FindFiles(FString Path, FString Filter, bool Files, bool Directory);
  • 1
  • 2
  • 3

.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;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
指定文件移动到某处(修改文件路径)#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
  • 1

.h

    UFUNCTION(BlueprintCallable, Category = "File operation")        static bool MoveFileTo(FString To, FString From);
  • 1
  • 2

.cpp

bool ACPP_Test::MoveFileTo(FString To, FString From){    return IFileManager::Get().Move(*To, *From);}
  • 1
  • 2
  • 3
  • 4
删除指定文件#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
  • 1

.h

UFUNCTION(BlueprintCallable, Category = "File operation")        static bool DeleteFile(FString FilePath);
  • 1
  • 2

.cpp

bool ACPP_Test::DeleteFile(FString FilePath){    return IFileManager::Get().Delete(*FilePath);}
  • 1
  • 2
  • 3
  • 4
打开指定文件#include "Runtime/Core/Public/HAL/FileManagerGeneric.h"
  • 1

.h

    UFUNCTION(BlueprintCallable, Category = "File operation")        static void   OpenFile(FString FilePath);
  • 1
  • 2

.cpp

void ACPP_Test::OpenFile(FString FilePath){    FPlatformProcess::CreateProc(*FilePath, nullptr, true, false, false, nullptr, 0, nullptr, nullptr);}
  • 1
  • 2
  • 3
  • 4
创建文件夹

.h

    UFUNCTION(BlueprintCallable, Category = "File operation")        static void CreateDic(FString filePath);
  • 1
  • 2

.cpp

void ACPP_Test::CreateDic(FString filePath){    IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();    PlatformFile.CreateDirectory(*filePath);}
  • 1
  • 2
  • 3
  • 4
  • 5
删除文件夹

.h

UFUNCTION(BlueprintCallable, Category = "File operation")        static void DeleteDic(FString filePath);
  • 1
  • 2

.cpp

void ACPP_Test::DeleteDic(FString filePath){    IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();    PlatformFile.DeleteDirectory(*filePath);}
  • 1
  • 2
  • 3
  • 4
  • 5





2 个回复

倒序浏览
奈斯,很赞
回复 使用道具 举报
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马