-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_manager.py
151 lines (106 loc) · 3.8 KB
/
file_manager.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import os
from shutil import copy, rmtree
class FileManager():
"""
"""
def __init__(self):
"""
"""
pass
def copy_file(self):
"""
"""
file_name = input("file name -> ")
directory_name = input("directory name -> ")
print("Copying file...")
if os.path.isfile(file_name):
copy(file_name, directory_name)
print(f"{file_name} has been copied.")
else:
print(f"{file_name} is already there.")
def create_directory(self):
"""
"""
directory_name = input("directory name -> ")
parent_directory = os.getcwd()
directory_path = os.path.join(parent_directory, directory_name)
if not os.path.exists(directory_name):
os.mkdir(directory_path)
print(f"{directory_name} has been created.")
elif os.path.exists(directory_path):
print(f"{directory_name} already exists.")
def create_file(self):
"""
"""
file_name = input("file name -> ")
content = input("content -> ")
print("Creating file...")
if not os.path.exists(file_name):
file = open(file_name, "w")
file.write(content)
file.close()
print(f"{file_name} has been created.")
else:
print(f"{file_name} already exists.")
def delete_directory(self):
"""
"""
directory_name = input("directory name -> ")
if os.path.exists(directory_name):
try:
os.rmdir(directory_name)
print(f"{directory_name} has been deleted.")
except OSError:
print(f"{directory_name} is not empty.")
print(f"{directory_name} was not deleted.")
elif not os.path.exists(directory_name):
print(f"{directory_name} does not exists.")
def delete_file(self):
"""
"""
file_name = input("file name -> ")
print("Deleting file...")
if os.path.isfile(file_name):
os.remove(file_name)
print(f"{file_name} has been deleted.")
else:
print(f"{file_name} does not exists.")
def find_file(self):
pass
def open_file(self):
"""
"""
file_name = input("file name -> ")
print("Opening file...")
if os.path.exists(file_name):
print(f"_________{file_name}_________")
file = open(file_name, "r")
print(file.read())
elif not os.path.exists(file_name):
print(f"{file_name} does not exist.")
def rename_directory(self):
"""
"""
old_directory_name = input("old directory name -> ")
new_directory_name = input("new directory name -> ")
print("Renaming directory...")
if os.path.exists(old_directory_name):
os.rename(old_directory_name, new_directory_name)
print("This directory has been renamed.")
elif not os.path.exists(old_directory_name):
print(f"{old_directory_name} cannot be found.")
elif os.path.exists(new_directory_name):
print(f"{new_directory_name} already exists.")
def rename_file(self):
"""
"""
old_file_name = input("old file name -> ")
new_file_name = input("new file name -> ")
print("Renaming file...")
if os.path.exists(old_file_name):
os.rename(old_file_name, new_file_name)
print("This file has been renamed.")
elif not os.path.exists(old_file_name):
print(f"{old_file_name} cannot be found.")
elif os.path.exists(new_file_name):
print(f"{old_file_name} already exists.")