-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileManager.py
More file actions
31 lines (25 loc) · 868 Bytes
/
FileManager.py
File metadata and controls
31 lines (25 loc) · 868 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
29
30
31
import glob
import os
class FileManager:
@staticmethod
def parse(path_pattern):
list_paths = glob.glob(path_pattern, recursive=True)
if not list_paths:
print("указан пустой список файлов")
for path in list_paths:
if os.path.isdir(path):
print(f"{path} не является файлом")
elif not path.endswith(".pas"):
print(f"{os.path.basename(path)} не является файлом pascal")
else:
yield path
@staticmethod
def load(path):
with open(path, 'r') as file:
document = file.read()
return document
@staticmethod
def save(path, document):
with open(path, "w") as file:
for line in document:
file.write(line + '\n')