2020-04-24 20:33:55 +02:00
|
|
|
from os.path import isfile as DoesFileExist
|
|
|
|
|
|
|
|
from .DataStructureManupulations import ConvertToStandardPathFormat
|
|
|
|
|
2020-04-25 16:11:36 +02:00
|
|
|
|
2020-04-24 20:33:55 +02:00
|
|
|
def ReadTextFile(FilePath):
|
|
|
|
FilePath = ConvertToStandardPathFormat(FilePath)
|
|
|
|
if DoesFileExist(FilePath) is True:
|
|
|
|
File = open(FilePath)
|
|
|
|
ReadFile = File.read()
|
|
|
|
File.close()
|
|
|
|
return ReadFile
|
|
|
|
else:
|
|
|
|
return ''
|
2020-04-25 16:11:36 +02:00
|
|
|
|
|
|
|
|
2020-04-24 20:33:55 +02:00
|
|
|
def ReadlinesTextFile(FilePath):
|
|
|
|
String = ReadTextFile(FilePath)
|
|
|
|
return String.split('\n')
|
|
|
|
|
2020-04-25 16:11:36 +02:00
|
|
|
|
2020-04-24 20:33:55 +02:00
|
|
|
def WriteTextFiles(FilePath, Text):
|
|
|
|
if type(Text) != str:
|
|
|
|
Text = '\n'.join(Text)
|
|
|
|
File = open(FilePath, 'w')
|
|
|
|
File.write(Text)
|
|
|
|
File.close()
|
|
|
|
|
2020-04-25 16:11:36 +02:00
|
|
|
|
2020-04-24 20:33:55 +02:00
|
|
|
def WriteBinaryToFile(Filepath, Data):
|
2020-04-25 16:11:36 +02:00
|
|
|
File = open(Filepath, 'wb')
|
2020-04-24 20:33:55 +02:00
|
|
|
File.write(Data)
|
|
|
|
File.close()
|