-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.py
More file actions
28 lines (23 loc) · 861 Bytes
/
Copy pathFile.py
File metadata and controls
28 lines (23 loc) · 861 Bytes
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
import os
class File:
def __init__(self,readfile,writefile):
self.readfile = readfile
self.writefile = writefile
def DetectFile(self):
if os.path.exists(self.readfile) and self.readfile.lower().endswith('.txt'):
return True
else:
return False
def ReadFile(self):
filelist = []
with open(self.readfile, 'r', encoding='utf-8') as file:
for num, line in enumerate(file, 1):
filelist.append(line.strip())
return filelist
def WriteFile(self, content):
with open(self.writefile, 'w', encoding='utf-8') as file:
file.write(content)
def AddFile(self, content):
with open(self.writefile, 'a', encoding='utf-8') as file:
file.write('\n\n')
file.write(content)