forked from Louis-me/appiumn_auto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperateFile.py
57 lines (53 loc) · 1.73 KB
/
OperateFile.py
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
__author__ = 'shikun'
import os
class OperateFile:
#method(r,w,a)
def __init__(self, file, method='w+'):
self.file = file
self.method = method
self.fileHandle = None
def write_txt(self, line):
OperateFile(self.file).check_file()
self.fileHandle = open(self.file, self.method)
self.fileHandle.write(line + "\n")
self.fileHandle.close()
def read_txt_row(self):
resutl = ""
if OperateFile(self.file).check_file():
self.fileHandle = open(self.file, self.method)
resutl = self.fileHandle.readline()
self.fileHandle.close()
return resutl
def read_txt_rows(self):
if OperateFile(self.file).check_file():
self.fileHandle = open(self.file, self.method)
file_list = self.fileHandle.readlines()
for i in file_list:
print(i.strip("\n"))
self.fileHandle.close()
def check_file(self):
if not os.path.isfile(self.file):
# print('文件不存在' + self.file)
# sys.exit()
return False
else:
return True
# print("文件存在!")
def mkdir_file(self):
if not os.path.isfile(self.file):
f = open(self.file, self.method)
f.close()
print("创建文件成功")
else:
print("文件已经存在")
def remove_file(self):
if os.path.isfile(self.file):
os.remove(self.file)
print("删除文件成功")
else:
print("文件不存在")
# if __name__ == '__main__':
# bf = OperateFile("text.xml")
# if bf.check_file() == False:
# bf.mkdir_file()
# bf.write_txt("111")