-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile operations.py
More file actions
43 lines (35 loc) · 1.06 KB
/
File operations.py
File metadata and controls
43 lines (35 loc) · 1.06 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
import os
import os.path
def search(keyword):
dir_list = os.listdir()
result_list = []
for each in dir_list:
if os.path.isdir(each):
search(each)
elif keyword in each:
result_list.append(os.curdir+'each')
return result_list
def create(file_name, location, content):
os.chdir(location)
with open(file_name, "w") as f:
f.write(content)
def start_working():
while True:
dir = input('working dir:')
if not os.path.isdir(dir):
print('dir do not exist')
os.chdir(dir)
type = input('input 1 to search, 2 to create and 3 to quit: ')
if type == 1:
keyword = input('keyword of file: ')
pass
search(keyword)
elif type == 2:
file_name = input('name of file: ')
location = input('where you want to create the file: ')
content = input('content: \n')
create(file_name, location, content)
elif type == 3:
break
else:
print('not defined')