-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.py
More file actions
67 lines (49 loc) · 1.42 KB
/
FileManager.py
File metadata and controls
67 lines (49 loc) · 1.42 KB
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
'''
============================================================================
Class for loading files and reading directories
(C++ version)
3/11/2014
SDLTutorials.com
Tim Jones
(Python3 version)
22/03/2016
www.inf.ufsm.br/~rtrindade
Rafael Gauna Trindade
==============================================================================
'''
from os import listdir, getcwd
from Log import Log
DIR_SEPARATOR = "/"
class FileManager:
def SetContents(self, Filename, Content, Relative=True):
if Filename == "":
return False
if Relative:
Filename = getcwd() + DIR_SEPARATOR + Filename
with open(Filename, 'w') as FileHandle:
FileHandle.write(Content)
return True
def GetContents(self, Filename, Relative=True):
if Filename == "":
return False
if Relative:
Filename = getcwd() + DIR_SEPARATOR + Filename
Content = None
with open(Filename) as FileHandle:
Content = FileHandle.read()
return Content
def GetFilesInFolder(self, Folder):
List = []
Path = getcwd()
if Folder != "":
Path += DIR_SEPARATOR + Folder
try:
for Filename in listdir(Path):
List.append(Path + DIR_SEPARATOR + Filename)
except:
Log("Unable to open directory :",Path)
return List
def GetFilenameWithoutExt(self, Filename):
return Filename[Filename.rfind(DIR_SEPARATOR)+1:Filename.rfind('.')]
def GetFilenameExt(self, Filename):
return Filename[Filename.rfind('.')+1:]