-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadTXT.cpp
81 lines (61 loc) · 2 KB
/
ReadTXT.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Fill out your copyright notice in the Description page of Project Settings.
#include "ReadTXT.h"
#include <Runtime\Core\Public\Misc\FileHelper.h>
#include <Runtime\Core\Public\HAL\PlatformFilemanager.h>
#include <Runtime\Core\Public\HAL\FileManagerGeneric.h>
#include "Containers/UnrealString.h"
FString UReadTXT::LoadFileToString(FString Filename)
{
FString directory = FPaths::GameSourceDir();
FString results;
IPlatformFile& file = FPlatformFileManager::Get().GetPlatformFile();
if (file.CreateDirectory(*directory))
{
FString myFile = directory + "/" + Filename;
FFileHelper::LoadFileToString(results, *myFile);
}
return results;
}
TArray<FString> UReadTXT::LoadFileToArray(FString Filename)
{
FString directory = FPaths::GameSourceDir();
TArray<FString> results;
IPlatformFile& file = FPlatformFileManager::Get().GetPlatformFile();
if (file.CreateDirectory(*directory))
{
FString myFile = directory + "/" + Filename;
FFileHelper::LoadFileToStringArray(results, *myFile);
}
return results;
}
TArray<FString> UReadTXT::GetTXTFromDir(FString Filename)
{
// Init ouput
TArray<FString> files;
files.Empty();
// to have the same number of index
TArray<TArray<FString>> output;
// point to source directory of the game
FString Directory = FPaths::GameSourceDir();
if (FPaths::DirectoryExists(Directory))
{ // Init the path : source/[directory]/*.txt
FString path = Directory + "*.txt";
// search for every files with the .txt extention
FFileManagerGeneric::Get().FindFiles(files, *path, true, false);
// fill the list with empty list of strings
TArray<FString> emptyList;
output.Init({emptyList}, files.Num());
for (int i = 0; i < files.Num(); i++)
{
// create the path for every files
files[i] = Directory + files[i];
//UE_LOG(LogTemp, Warning, TEXT("%s"), *output[i]);
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Directory Not Found"));
}
return files;
//return FilePathList;
}